I am trying to implement some cache in my application. The situation is like this, objects can be added to a cache, the cache can be invalidated on some conditions, and some user may retrieve some object from the cache. I don't want the process to break with all these activities may happen all at the same time. I therefore thought about synchronization. However, unable to find a better way to apply synchronization to it and keep a best performance possible. Can someone please help what should I do to apply synchronization in this case. I put some pseudo-code below for my CacheUtility class:
public class CacheUtililty()
{
public void addCache(Cache myCache, Object obj)
{
//add obj to myCache;
}
public void invalidCache(Cache myCache)
{
// invalidate myCache;
}
public Object getCache(Cache myCache,
String key)
{
//Object obj=myCache.getCache(key);
//return obj;
}
}