TimedCacheDataSource<T> is a key-value data source that implements
DeleteDataSource. It acts as a TLRU cache (Time aware Least Recently Used) over a contained data source by implementing a local in-memory storage to cache values of type
// Swift// custom data sourcelet customDataSource = MyCustomDataSource()// timed-cache data source with a time validation of 60 secondslet dataSource = TimedCacheDataSource(customDataSource, expiryInterval: 60)// first get, fetching from customDataSourcedataSource.get("object")// second get within 60 secs, value returned comes from the cachedataSource.get("object")// performs a put in the customDataSource and updates the cached valuedataSource.put(myObject, forId: "object")// deletes the delete in both customDataSource and in the cachedataSource.delete("object")
Note that the example above is using the extension methods of DataSoruce that encapsulate queries of type
All queries must adopt the
KeyQuery interface as the
TimedCacheDataSource<T> is based on a key-value pattern. Otherwise, the cache is just ignored and all queries are forwarded to the contained data source.
TimedCacheDataSource<T> depends on the contained data source.
TimedCacheDataSource<T> doesn't raise errors on its own. However, if the contained data source returns an error, all cached values for the given queried key are removed and the error is returned.