Cache Object Pattern
The concept of keeping a copy of an object in some form of memory with the goal of providing a faster response time to a client request is called caching. A cache management strategy must be developed to decide on the optimal number of objects to be cached and how long these objects are to be kept in the memory.
The existence of the cache must remains transparent to the client.
public class Cache { //is works just based on a number. It can work based on time, etc. private final static int CACHE_SIZE = 100; List cache; public ItemCache() { cache = new ArrayList(); } public String getFromCache(...) { //check the cache and return the item } public void addToCache(...) { //add to cache based on CACHE_SIZE } }
The service code that client will use should look like this:
public Item getItem(...) { cache = new Cache(); if (cache.getFromCache(...) != null) { //is in the cache so return it } else { //get it from db or ... and add it to cache cache.addToCache(...); } }
page_revision: 0, last_edited: 1215348178|%e %b %Y, %H:%M %Z (%O ago)





