-
Notifications
You must be signed in to change notification settings - Fork 1
CustomLocalStorage
By default, the library is using SimpleHalStorage which stores models locally and overrides them every time a new version of the resource is fetched.
If cacheStrategy is set to CacheStrategy.ETAG, e-tag based caching is used, see more in Etag based caching docs.
When there is a need for custom behaviour of local storage, a custom implementation of HalStorage can be provided in DatastoreConfig decorator:
@DatastoreConfig({
...
cacheStrategy: CacheStrategy.CUSTOM,
storage: new SomeCustomStorage()
})In this case, cacheStrategy must be set to CacheStrategy.CUSTOM, and an instance of HalStorage must be provided in storage property.
class SomeCustomStorage extends HalStorage {}If there is a need for some requests to be returned from local cache instead of making a request, SomeCustomStorage could implement makeGetRequestWrapper in a way that for those requests intercepts the original request, cancels it, and returns the value from the local cache.
One of the implementations of a custom HalStorage can be seen in Cacheable storage pull request