Skip to content

An object cache to store objects temporarily & locally for .NET applications

License

Notifications You must be signed in to change notification settings

armannaj/LocalObjectCache

Repository files navigation

LocalObjectCache

NuGet

An object cache to store objects temporarily & locally for .NET applications.

Required

Usages

  • To store the HTTP response back, in order to not hit an API endpoint too much (avoiding HTTP 429 status code)

How does it work?

Internally, it uses LiteDB to store objects in a local file.

How to use

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:

InsertOne<T>

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))

GetOne<T>

Gets an object from the cache with the given predicate (in lambda format)

GetOne<ExchangeRate>(x => x.BaseCurrency.Equals("USD")) 

InsertMany(IEnumerable<T>)

InsertMany<ExchangeRate>(new [] { new ExchangeRate("USD", "EUR", 0.96),  new ExchangeRate("USD", "AUD", 1.50)})

GetMany

GetMany<ExchangeRate>(x => x.BaseCurrency.Equals("USD"))

About

An object cache to store objects temporarily & locally for .NET applications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages