Galaxis In-Memory Cache
A Galaxis cache that stores state in memory and is observable via Redux DevTools.
Installation
yarn add @galaxis/in-memory-cache
You need to install Galaxis Core as well, directly or indirectly.
The library is compiled to modern JS, but it should work in all reasonable browsers with the help of properly configured Babel.
Public API
⚠ Anything that is not documented here is not considered a part of public API and may change at any time.
InMemoryCache
Implements Cache
.
const inMemoryCache = new InMemoryCache({ emptyData, initialState, enableDevTools });
Arguments
Name | Type | Description | Required |
---|---|---|---|
emptyData | TCacheData |
A value that conforms to TCacheData , that is considered to be empty. E.g. {entities: {}}
|
Yes |
initialState | CacheState<TCacheData, ErrorObject > |
A value from cache.extract() , most likely from SSR. |
No |
enableDevTools | boolean |
Enable Redux DevTools integration. | No |
cache.extract()
Returns the cache state in serializable form. Uses serialize-error to convert errors into serializable objects.
If the cache is split, returns the state with the least amount of changes. It should never happen during SSR, and on the client side it means that the extracted state won't contain any optimistic data (but will contain everything else).
const state = cache.extract();
Return value
CacheState<TCacheData, ErrorObject >
Important types
CacheState
Internal state of the cache.
Name | Type | Description |
---|---|---|
data | TCacheData |
Cache data. |
errors | Record<string, E | undefined> |
Cached errors. E is Error by default. |