mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 04:26:58 +00:00
document cache implementations
This commit is contained in:
parent
fa68751a19
commit
e7feca8784
1 changed files with 29 additions and 0 deletions
|
@ -622,6 +622,35 @@ marginはそのコンポーネントを使う側が設定する
|
|||
### indexというファイル名を使うな
|
||||
ESMではディレクトリインポートは廃止されているのと、ディレクトリインポートせずともファイル名が index だと何故か一部のライブラリ?でディレクトリインポートだと見做されてエラーになる
|
||||
|
||||
### Memory Caches
|
||||
|
||||
Sharkey offers multiple memory cache implementations, each meant for a different use case.
|
||||
The following table compares the available options:
|
||||
|
||||
| Cache | Type | Consistency | Persistence | Data Source | Cardinality | Eviction | Description |
|
||||
|---------------------|-----------|-------------|-------------|-------------|-------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `MemoryKVCache` | Key-Value | None | None | Caller | Single | Lifetime | Implements a basic in-memory Key-Value store. The implementation is entirely synchronous, except for user-provided data sources. |
|
||||
| `MemorySingleCache` | Single | None | None | Caller | Single | Lifetime | Implements a basic in-memory Single Value store. The implementation is entirely synchronous, except for user-provided data sources. |
|
||||
| `RedisKVCache` | Key-Value | Eventual | Redis | Callback | Single | Lifetime | Extends `MemoryKVCache` with Redis-backed persistence and a pre-defined callback data source. This provides eventual consistency guarantees based on the memory cache lifetime. |
|
||||
| `RedisSingleCache` | Single | Eventual | Redis | Callback | Single | Lifetime | Extends `MemorySingleCache` with Redis-backed persistence and a pre-defined callback data source. This provides eventual consistency guarantees based on the memory cache lifetime. |
|
||||
| `QuantumKVCache` | Key-Value | Immediate | None | Callback | Multiple | Lifetime | Combines `MemoryKVCache` with a pre-defined callback data source and immediate consistency via Redis sync events. The implementation offers multi-item batch overloads for efficient bulk operations. **This is the recommended cache implementation for most use cases.** |
|
||||
|
||||
Key-Value caches store multiple entries per cache, while Single caches store a single value that can be accessed directly.
|
||||
Consistency refers to the consistency of cached data between different processes in the instance cluster: "None" means no consistency guarantees, "Eventual" caches will gradually become consistent after some unknown time, and "Immediate" consistency ensures accurate data ASAP after the update.
|
||||
Caches with persistence can retain their data after a reboot through an external service such as Redis.
|
||||
If a data source is supported, then this allows the cache to directly load missing data in response to a fetch.
|
||||
"Caller" data sources are passed into the fetch method(s) directly, while "Callback" sources are passed in as a function when the cache is first initialized.
|
||||
The cardinality of a cache refers to the number of items that can be updated in a single operation, and eviction, finally, is the method that the cache uses to evict stale data.
|
||||
|
||||
#### Selecting a cache implementation
|
||||
|
||||
For most cache uses, `QuantumKVCache` should be considered first.
|
||||
It offers strong consistency guarantees, multiple cardinality, and a cleaner API surface than the older caches.
|
||||
An alternate cache implementation should be considered if any of the following apply:
|
||||
* The data is particularly slow to calculate or difficult to access. In these cases, either `RedisKVCache` or `RedisSingleCache` should be considered.
|
||||
* If stale data is acceptable, then consider `MemoryKVCache` or `MemorySingleCache`. These synchronous implementations have much less overhead than the other options.
|
||||
* There is only one data item, or all data items must be fetched together. Using `MemorySingleCache` or `RedisSingleCache` could provide a cleaner implementation without resorting to hacks like a fixed key.
|
||||
|
||||
## CSS Recipe
|
||||
|
||||
### Lighten CSS vars
|
||||
|
|
Loading…
Add table
Reference in a new issue