I wanna cache an array of object that is not more than 300 items, It's read only array. First I implemented it in Redis with StackExchange.Redis client, and then implement it by static variable. Static variable has e better performance and get less CPU usage instead of Redis, but I do not know that is it good way or not?
It’s possible to use Redis as both a cache and a session store in a single setup as shown in the picture below. In this design, the application layer accesses and maintains the data in the cache. Therefore, all the sessions running inside the application access the same data stored in the cache.
It is certainly slower than just storing the data in local memory (since it involves socket roundtrips to fetch/store the data). However, it also brings some interesting properties: Redis can be accessed by all the processes of your applications, possibly running on several nodes (something local memory cannot achieve).
} What's the advantage Redis have? Redis is a remote data structure server. It is certainly slower than just storing the data in local memory (since it involves socket roundtrips to fetch/store the data). However, it also brings some interesting properties:
We can't use simple cache in server less as we can't be sure our request gets served at same container where our simple cache is stored. In this case, we have to use redis as it stores cache at remote location & we can access that even container changes in server less architecture.
If the data is truly static, then while yes you could store the data in redis, you would not usually go to redis every time - so it would probably end up having a local cache anyway (with redis as a second level cache). static
can work fine for things like a read-only array, and this will be unbeatable in terms of performance. However, if you start mutating the contents of a static
member: expect pain.
In one of my project we used redis for caching and also we used local cache (Not static variable but you can also use static variable).
But it really depends on your requirements. We used redis because we had web farm and we wanted to share data between servers. We also used local caching (see MemoryCache) to increase performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With