|
| 1 | +# DotNet Core Memory Cache Service |
| 2 | + |
| 3 | +## Purpose |
| 4 | + |
| 5 | +The DotNet Core [Microsoft.Extensions.Caching.Memory](https://github.com/aspnet/Caching/tree/dev/src/Microsoft.Extensions.Caching.Memory) lacks the ability to easily remove groups of items from the cache. This is a [know limitation](https://github.com/aspnet/Caching/issues/187) which apparently there is no interest in addressing. |
| 6 | + |
| 7 | +## Compatability |
| 8 | + |
| 9 | +* NET Standard + Platform Extensions,Version=v2.0 |
| 10 | +* NET Core + Platform Extensions,Version=v2.0 |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +* When adding items to the cache, specify the group they belong to |
| 15 | +* Remove a group of cached items by group name |
| 16 | +* Remove all items in the cache |
| 17 | +* Specify the item's cache lifetime in seconds when adding an item to the cache |
| 18 | +* Synchronous and Asynchonous factory lamda functions |
| 19 | + |
| 20 | +## Future |
| 21 | +Please feel free to make a pull request. :) |
| 22 | +* Implement other methods from IMemoryCache |
| 23 | +* Unit tests |
| 24 | +* Query the cache status |
| 25 | + |
| 26 | +## Example |
| 27 | +Run the included example dotnet console application which demonstrates a simulated database of products where accessing the database is an expensive operation, so these query results are meant to be cached in a product provider. |
| 28 | + |
| 29 | +When a change is made to the product database, the cache has items removed from that product's categories, so when future requests for product lists will pick up the new product immediately. |
| 30 | + |
| 31 | +The console output shows that the first time the beer list is queries, an expensive database operation happens, and subsequent request are served from the cache. |
| 32 | + |
| 33 | +Once a new item is added to the category, the cache for that category becomes invalidated, and the next reqeust for the beer list correctly results in another expensive database hit. |
| 34 | + |
| 35 | +## Getting Started |
| 36 | + |
| 37 | +If deploying to a server farm and you want to stick with in-memory cache, be sure to configure the load balancer to use sticky sessions. |
0 commit comments