caching - Redis cache strategy for MySql with Spring Cache -
currently i'm using redis following purpose:
- cache web pages.
- cache sql query resulting in single result.
for example:
@cacheable(value = "membercache", key = "#username.concat('')") public membermodel findbyusername(string username) { return memmapper.findbyusername(username); }
but problem how cache sql query resulting in multiple results.
e.g.:
public list<membermodel> findwhichagebiggerthan(int age) { return memmapper.agebiggerthan(age); }
now result turns out become list
. of course can cache result too, if new user registers system, result of query might changed. if happens, cache stale. how solve problems this?
thank pretty pretty much!
instead of using list can use redis hash :
your method this:
public map<string, membermodel> findwhichagebiggerthan(int age) { // return map key string(may user id) , actual membermodel }
this whole map can saved against super key "members" , individual data can saved student1, student2 keys below
hset members student1 membermodel1 student2 membermodel2
to add other data use above command paricular data like
hset members student_new membermodel_new
here members add/update existing "nembers" key new data.
Comments
Post a Comment