Database primary keys as cache keys?
I am planning to use Coherence initially to provide basic caches that sit in front of database tables. I plan to implement various CacheStores that will execute the db code and create the objects that will sit in those caches.
I am trying to figure out what the best approach would be for designing the cache keys. An obvious choice would be to use the database primary keys. But this has drawbacks. It will require the application to know the primary key before it asks the cache for a particular object. This is not really a new problem, but the introduction of Coherence may open up some new options in solving this.
Using db primary keys as cache keys also adds complication when new objects are created. The applicaiton will create the object and put it in the cache. The put operation will call down to the store method of the CacheStore. At this point, no primary key has been created yet for the object. A primary key will not be created until the db code is executed. At which point, the key in the cache must be changed.
Is there a well-designed approach to solving this problem? Should db primary keys not be used as cache keys? If not, what are some other good options for cache keys?
Any ideas? Thanks.