All Projects → alastairtree → Lazycache

alastairtree / Lazycache

Licence: mit
An easy to use thread safe in-memory caching service with a simple developer friendly API for c#

Projects that are alternatives of or similar to Lazycache

Craft Blitz
Intelligent static page caching for creating lightning-fast sites with Craft CMS.
Stars: ✭ 118 (-86.9%)
Mutual labels:  cache, performance
Scaffeine
Thin Scala wrapper for Caffeine (https://github.com/ben-manes/caffeine)
Stars: ✭ 195 (-78.36%)
Mutual labels:  cache, performance
Laravel Responsecache
Speed up a Laravel app by caching the entire response
Stars: ✭ 1,874 (+107.99%)
Mutual labels:  cache, performance
Django Cachalot
No effort, no worry, maximum performance.
Stars: ✭ 790 (-12.32%)
Mutual labels:  cache, performance
Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+488.68%)
Mutual labels:  cache, performance
Quitnow Cache
A collection to store data for a given time
Stars: ✭ 109 (-87.9%)
Mutual labels:  cache, performance
Hitchcock
The Master of Suspense 🍿
Stars: ✭ 167 (-81.47%)
Mutual labels:  cache, lazy
Pomodoro
A simple WordPress translation cache
Stars: ✭ 47 (-94.78%)
Mutual labels:  cache, performance
Guzzle Cache Middleware
A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.
Stars: ✭ 325 (-63.93%)
Mutual labels:  cache, performance
Ristretto
A high performance memory-bound Go cache
Stars: ✭ 3,584 (+297.78%)
Mutual labels:  cache, performance
Fast React Render
[DEPRECATED] Use last versions of React and Node.js for better performance
Stars: ✭ 102 (-88.68%)
Mutual labels:  cache, performance
Bloom
🌸 HTTP REST API caching middleware, to be used between load balancers and REST API workers.
Stars: ✭ 553 (-38.62%)
Mutual labels:  cache, performance
Kirby3 Autoid
Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
Stars: ✭ 58 (-93.56%)
Mutual labels:  cache, performance
Laravel Blink
Cache that expires in the blink of an eye
Stars: ✭ 114 (-87.35%)
Mutual labels:  cache, performance
Ansible Role Memcached
Ansible Role - Memcached
Stars: ✭ 54 (-94.01%)
Mutual labels:  cache, performance
Fragment Cache
WordPress plugin for partial and async caching.
Stars: ✭ 135 (-85.02%)
Mutual labels:  cache, performance
Wordpress Rest Cache
WordPress Plugin to lazy cache HTTP requests in database and update via cron.
Stars: ✭ 8 (-99.11%)
Mutual labels:  cache, performance
Laravel Partialcache
Blade directive to cache rendered partials in laravel
Stars: ✭ 205 (-77.25%)
Mutual labels:  cache, performance
React Esi
React ESI: Blazing-fast Server-Side Rendering for React and Next.js
Stars: ✭ 537 (-40.4%)
Mutual labels:  cache, performance
Once
A magic memoization function
Stars: ✭ 821 (-8.88%)
Mutual labels:  cache, performance

Lazy Cache

Build status AppVeyor tests NuGet Nuget

Lazy cache is a simple in-memory caching service. It has a developer friendly generics based API, and provides a thread safe cache implementation that guarantees to only execute your cachable delegates once (it's lazy!). Under the hood it leverages Microsoft.Extensions.Caching and Lazy to provide performance and reliability in heavy load scenarios.

Download

LazyCache is available using nuget. To install LazyCache, run the following command in the Package Manager Console

PM> Install-Package LazyCache

Quick start

See the quick start wiki

Sample code

// Create our cache service using the defaults (Dependency injection ready).
// By default it uses a single shared cache under the hood so cache is shared out of the box (but you can configure this)
IAppCache cache = new CachingService();

// Declare (but don't execute) a func/delegate whose result we want to cache
Func<ComplexObjects> complexObjectFactory = () => methodThatTakesTimeOrResources();

// Get our ComplexObjects from the cache, or build them in the factory func 
// and cache the results for next time under the given key
ComplexObjects cachedResults = cache.GetOrAdd("uniqueKey", complexObjectFactory);

As you can see the magic happens in the GetOrAdd() method which gives the consumer an atomic and tidy way to add caching to your code. It leverages a factory delegate Func and generics to make it easy to add cached method calls to your app.

It means you avoid the usual "Check the cache - execute the factory function - add results to the cache" pattern, saves you writing the double locking cache pattern and means you can be a lazy developer!

What should I use it for?

LazyCache suits the caching of database calls, complex object graph building routines and web service calls that should be cached for performance. Allows items to be cached for long or short periods, but defaults to 20 mins.

.Net framework and dotnet core support?

The latest version targets netstandard 2.0. See .net standard implementation support

For dotnet core 2, .net framwork net461 or above, netstandard 2+, use LazyCache 2 or above.

For .net framework without netstandard 2 support such as net45 net451 net46 use LazyCache 0.7 - 1.x

For .net framework 4.0 use LazyCache 0.6

Features

  • Simple API with familiar sliding or absolute expiration
  • Guaranteed single evaluation of your factory delegate whose results you want to cache
  • Strongly typed generics based API. No need to cast your cached objects every time you retieve them
  • Stops you inadvertently caching an exception by removing Lazys that evaluate to an exception
  • Thread safe, concurrency ready
  • Async compatible - lazy single evaluation of async delegates using GetOrAddAsync()
  • Interface based API and built in MockCache to support test driven development and dependency injection
  • Leverages a provider model on top of IMemoryCache under the hood and can be extended with your own implementation
  • Good test coverage

Documentation

Sample Application

See CacheDatabaseQueriesApiSample for an example of how to use LazyCache to cache the results of an Entity framework query in a web api controller. Watch how the cache saves trips to the database and results are returned to the client far quicker from the in-memory cache

Contributing

If you have an idea or want to fix an issue please open an issue on Github to discuss it and it will be considered.

If you have code to share you should submit a pull request: fork the repo, then create a branch on that repo with your changes, when you are happy create a pull Request from your branch into LazyCache master for review. See https://help.github.com/en/articles/creating-a-pull-request-from-a-fork.

LazyCache is narrow in focus and well established so unlikely to accept massive changes out of nowhere but come talk about on GitHub and we can all collaborate on something that works for everyone. It is also quite extensible so you may be able to extend it in your project or add a companion library if necessary.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].