1

Need to add global variable in REDIS Cache. For Ex: Consider an student, employee and Staff related application. Every role has a unique object. When student log in to the application we need to get student information from redis. Same for other roles log in too.

If we store all the details at time of application initialization, we no need to send request to get role related details. If we store it into session, that data will be checking by every users login. And also session id has been varied for every users.

Is it possible? If yes, How can we store the values at the time of application initialization?

LTA
  • 191
  • 3
  • 16

1 Answers1

2

First of all, since Redis is a cache, you are storing objects that may be evicted with time. When Redis becomes full, it will start clearing objects according to your eviction policy configuration.

Probably caching everything upon initialization is not the best course of action, I'd go with caching the objects when they are first requested, if they don't exist on Redis, store them for future retrievals. This way, if your Redis instance clears that object, your application logic will always find it (from cache or from local storage). That's called a Cache-Aside Pattern.

Your initialization logic varies depending on which technology / platform are you using. ASP.NET MVC 5 or lower has the Global.asax file, ASP.NET 5 MVC6 has the Startup.cs file.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47