0

I'm using ehCache to store users information. I set it as

usersDB = cacheManager.....withExpiry(ExpiryPolicyBuilder. timeToIdleExpiration(Duration.ofDays(1))));

My thought was that if a user won't use the system for 1 day, it will be removed from the cache. The problem is that the client (Android) has a widget that refreshes every day and for that to happen, I need to access the user's data: usersDB.get(email)....

I guess that such access initializes the idle timer, right? That means that the user will never be idle and will never be removed from the cache. Any idea how to overcome this?

Thanks

Amos
  • 1,321
  • 2
  • 23
  • 44
  • A cache of 1 day is most probably too long, you should keep data in the cache as long as people are using the site/application, and I doubt users are making a full 24 hours sessions on the site without pauses. – Nyamiou The Galeanthrope Apr 01 '20 at 16:46
  • Why don't your keep your cache in sync with DB. Everytime there is change, invalidate or update the cache. – Tarun Apr 01 '20 at 16:50
  • Thinking again I think your problem is that you are not considering client side cache, you can make a cache on client side and use a cache invalidation process to force the client to get the data again when it's cache data is outdated. You can look at how web browsers use caching (https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching) as an example. – Nyamiou The Galeanthrope Apr 01 '20 at 16:50
  • Thank you for replying. 1. I cache the user until he logs out. If he didn't, I give him grace period of 1 day before removal (lost user). 2. I do sync cache with DB but I prefer the cache for performance. The problem remains, the user will never be idle. 3. I will use client cache eventually, though the widget needs to get the up to date data anyway. – Amos Apr 01 '20 at 17:05

0 Answers0