From 22fd8ce2ac4cfccef1aa8d1af30a8af6c0011e60 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 2 May 2021 17:10:10 +0200 Subject: [PATCH] Changeset Signed-off-by: Eric Peterson --- .changeset/cool-cache-bro.md | 44 ++++++++++++++++++++++++++++++++++++ .github/styles/vocab.txt | 1 + 2 files changed, 45 insertions(+) create mode 100644 .changeset/cool-cache-bro.md diff --git a/.changeset/cool-cache-bro.md b/.changeset/cool-cache-bro.md new file mode 100644 index 0000000000..f86dc39339 --- /dev/null +++ b/.changeset/cool-cache-bro.md @@ -0,0 +1,44 @@ +--- +'@backstage/backend-common': minor +--- + +Introducing: a standard API for App Integrators to configure cache stores and Plugin Developers to interact with them. + +Two cache stores are currently supported. + +- `memory`, which is a very simple in-memory LRU cache, intended for local development. +- `memcache`, which can be used to connect to one or more memcache hosts. + +Configuring and working with cache stores is very similar to the process for database connections. + +```yaml +backend: + cache: + store: memcache + connection: + hosts: + - cache-a.example.com:11211 + - cache-b.example.com:11211 +``` + +```typescript +import { CacheManager } from '@backstage/backend-common'; + +// Instantiating a cache client for a plugin. +const cacheManager = CacheManager.fromConfig(config); +const somePluginCache = cacheManager.forPlugin('somePlugin'); +const defaultTtl = 3600; +const cacheClient = somePluginCache.getClient(defaultTtl); + +// Using the cache client: +const cachedValue = await cacheClient.get('someKey'); +if (cachedValue) { + return cachedValue; +} else { + const someValue = await someExpensiveProcess(); + await cacheClient.set('someKey', someValue); +} +await cacheClient.delete('someKey'); +``` + +Configuring a cache store is optional. Even when no cache store is configured, the cache manager will dutifully pass plugins a manager that resolves a cache client that does not actually write or read any data. diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt index 694226b8cc..ff856239bf 100644 --- a/.github/styles/vocab.txt +++ b/.github/styles/vocab.txt @@ -167,6 +167,7 @@ mailto maintainership makefile md +memcache microsite middleware minikube