Menu Cache Core – using in memory cache

Most of the apps we write have some data that not get updated frequently or not get updated at all. For example – suburb list, user roles, etc. We can avoid reading the database for all those entities by using a cached collection. if you do have to update the cache you can by using a cache.Remove(‘key’); below is the implementation I used for one of my entities (of course you can write fancier code:) )

Here is the simple implementation.

Easy ?

Now in the Startup.cs, maybe you can register it as a Singleton? I have not tested it out yet.

Whenever I need to refresh it I call _cacheService.Clear(), like below.

Happy coding

Leave a comment