• Post Reply Bookmark Topic Watch Topic
  • New Topic

Appropiate way to Update the cache  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

In our Application we are caching the Customer Data as to reduce the hits to DataBase .

But whenever a new Customer Data is added from the User Interface , what is the appropiate way to update the cache ??

Will it better to go for a Synchronous approach or Aynchronous approach ??

Please share your ideas .

Thanks in advance .
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use observer pattern for that. Suppose CacheManager class loads/refreshes data, register that as observer with DataUpdater class to update sequentially. This will be asynchronous approach and is the suggested one in case it takes more than a couple of seconds to refresh data.

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Thanks .
 
luri ron
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use observer pattern for that. Suppose CacheManager class loads/refreshes data, register that as observer with DataUpdater class to update sequentially. This will be asynchronous approach and is the suggested one in case it takes more than a couple of seconds to refresh data.


just want to point out one thing. observer/observee doesn't get you asynchronous. it is how you how implement the notify of the observer. asynchronous means that the thread submit a request without waiting for the request to be processed completly. as long as the request is accepted, the thread moves on to process next. if you are interested in result of request being processed, you will need to have another thread to process the results.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks , then what is the appropiate way to update the cache .
 
Ajay Saxena
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:Ok thanks , then what is the appropiate way to update the cache .


There's no correct answer.

The appropriate strategy depends on a lot of factors. You need to seek answers to the following(the list is not exhaustive though )

- What frequency does your data get updated
- What's the cost of object creation
- What's the size of the objects
- What frequency does the data get updated at
- Whether the application is clustered (multi-server)

Besides cache updation,you also need to think about a cache expiration strategy suitable to your application.

It could be a wise idea to do a detailed analysis of your application's requirements and design and then leverage the capabilities of the open source caches available in the development community,such as OS
cache,Memcached etc.

A discussion on different caching strategies could be found at
http://www.developer.com/design/article.php/3831821/Performance-Improvements-Caching.htm

-thanks
AS
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!