Caching Strategy in Relational Database and Redis
Caching Strategy in Relational Database and Redis
Introduction to Caching
Caching Strategies in Database
Introduction to Redis
Installation and Configuration
Redis Implementation
Redis vs Memcached
Conclusion
References
Introduction to Caching
To install Redis, we just need to download redis installer and extract it.
Once installed, Redis should be available by default under http://localhost:6379/.
To get Redis up and running in .NET application we need to add
ServiceStack.Redis library from Nuget Package Manager in our .NET project.
Once installed we can connect to redis server by using ‘RedisManagerPool’ class
provided by ServiceStack.Redis package and also specify the password required
to access redis server as shown below:
The ‘Set’ function saves the key value pair of key and data in redis cache server.
Redis Cache Vs Memcached
Memcached only supports a key value data structure which are mostly strings.
Redis however supports different data structures like string, hash, list, set and
sorted sets.
Memcached stores cached data in memory only and does not make use of disk
for storage but Redis makes use of disk memory when the storage in primary
memory is full.
Memcached performs better than Redis when the data to cache is static and
volume is low. But when the data starts to grow redis cache outperforms
Memcached.
Redis supports in-memory data persistence but Memcached doest not support
any form of data persistence.
Conclusion
Redis cache server improves the performance of a data heavy application where data
are frequently required to be fetched from database. Redis also helps us understand
how caching can help us provide fast responses for data that have been accessed
before.
Maintaining data consistency between data in cache and data in database is a
concern for redis cache. It can be mitigated by combining it with one of three write
cache strategies.
References
Cache -Aside pattern. (2018, January). Retrieved from Microsoft Azure:
https://docs.microsoft.com/en-us/azure/architecture/patterns/cache-aside
Caching Strategies. (n.d.). Retrieved from AWS amazon :
https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Strategies.html?
fbclid=IwAR1Jkps1w2DA3telsZAD4RIK_PWMwBvdrxP-
b2JgnduU1thnwMXbrePhWFw
Caching Strategies and How to Choose the Right One. (2017, August). Retrieved
from Codeahoy: https://codeahoy.com/2017/08/11/caching-strategies-and-how-
to-choose-the-right-one/
Introduction to Redis. (n.d.). Retrieved from redis:
https://redis.io/topics/introduction?fbclid=IwAR2imiZ-
ErCj4vWe0SBEiLY9zK2PiI3f1cKRFy95YuuJKUxRgFx1PCml58A
Redis or Memcached - How to select the Caching Strategy? (2019, March 7).
Retrieved from Eduonix: https://blog.eduonix.com/web-programming-
tutorials/redis-memcached-select-caching-strategy/
Simple and Fast .Net Web Services Framework. (n.d.). Retrieved from
ServiceStack: https://servicestack.net/redis?fbclid=IwAR2zsus_N8-
2FvqQbVTBNn9AYhb7H4m0mhg1Bk6fBKvpNBpKyNus67vLTjM
Any Queries?
Thank You