• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Cache Reference Information

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Stan, for your guidance.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh, good question.
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic