• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cache Reference Information  RSS feed

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application on which I am working caches some reference information (for example, a catalog of all available items) once the application is launched.

This cached information is refreshed every 3 minutes. During that interval, a certain item could be deleted (no longer available); but, that particular item could be selected by an application user because the item is still there for viewing.

How is the situation normally handled? Thanks for your guidance in advance.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if its selected it does not get deleted/removed from the cache.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I did not explain my question well.

An item may have been deleted from the list. But, that item in the list is available for viewing because the list is cached and gets refreshed every three minutes. During that three minutes, the deleted item may be selected by a user.

How is the situation usually handled?
 
Paul Clapham
Sheriff
Posts: 22712
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user tries to access an item that has been deleted, the software says "Sorry, that item has been deleted."
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An item may have been deleted from the list.


I'm not sure what this means. It sounds like you can delete something from the database or some other "golden" store but it's still in cache. Is that right?

This is a bit tricky. On update or delete events on the golden store you also have to invalidate, update or reload the cache. You might use a pub-sub design to decouple the updater from the cache.

If you have distributed caches across a cluster it gets even harder. Google for "java distributed cache" to find some ready-made solutions rather than trying to write one.

Is this going the right direction?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
User does not get item but a reference to the item. When user eventually tries to 'use' item by using the reference, he finds out item is gone.

Its really up to you though. It depends on how soon you want the user to know its gone. You cant let the user begin a transaction of some sort, then rip the item out from under them.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
User does not get item but a reference to the item. When user eventually tries to 'use' item by using the reference, he finds out item is gone.


Where would an object go while I'm holding a reference to it?
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Stan, for your guidance.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:


Where would an object go while I'm holding a reference to it?


lets pick another synonym

"User does not get item but a key to the item. When user eventually tries to 'use' item by using the key, he finds out item is gone."

i.e. the user only holds a key and the object must be retrieved with the key for each use.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I can sleep better knowing that.

I've often had a cache that is combined with the data fetch mechanism. So we get something like

Then you can discard the least recently used or the oldest entry in cache or anything older than 3 minutes and clients may notice the speed difference when something is in cache or not in cache but they won't do anything different.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly what I use. And I spawn a thread to clean up the old SoftReferences as they drop out of the ReferenceQueue.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So now I'm curious ... why the refresh or invalidate or whatever every three minutes?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
So now I'm curious ... why the refresh or invalidate or whatever every three minutes?


What you talking about stan?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original post: This cached information is refreshed every 3 minutes. Why?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, good question.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!