An object cache to store objects temporarily & locally for .NET applications.
- To store the HTTP response back, in order to not hit an API endpoint too much (avoiding HTTP 429 status code)
Internally, it uses LiteDB to store objects in a local file.
For a quick start, you can use the static Cache.Default
. It creates a cache with the following default settings:
- Object validity timespan: 24hours from the time of object insertion
- DB filename: cache.db
- DB file path: local executing directory
Alternatively, you can instantiate Cache
and configure it the way you want it and use it.
You can use Index
attribute on the properties that you want to use as ID or you want to enforce uniqueness in the cache.
The following methods help you to interact with the cache:
Inserts an object of type T into the cache. The cache validity starts from the time of insertion.
InsertOne<ExchangeRate>(new ExchangeRate("USD", "EUR", 0.96))
Gets an object from the cache with the given predicate (in lambda format)
GetOne<ExchangeRate>(x => x.BaseCurrency.Equals("USD"))
InsertMany<ExchangeRate>(new [] { new ExchangeRate("USD", "EUR", 0.96), new ExchangeRate("USD", "AUD", 1.50)})
GetMany<ExchangeRate>(x => x.BaseCurrency.Equals("USD"))