- I have a bunch of objects all of one class which I want to store in the web cache.
- There could be a few hundred of these objects.
- I want objects to have their own individual expiry times, and expire from the cache individually.
- I want to be able to tell how many of these objects are in the cache, and iterate over these objects alone (regardless of other types in the cache).
Initially I thought about storing a generic collection in the cache, and just inserting the objects into the collection when needed. This is nice and tidy, and would make iteration easy. However, this wouldn't allow each of the objects to expire individually (the whole collection would expire). I suppose I would have to create my own expiry mechanism and 'garbage collection' in this case.
My second thought was to just store each of the objects as first class citizens of the cache. This would obviously allow them to expire individually, but seems a bit messy. How to iterate over them? Perhaps just iterate over the whole cache, and look for the right types (not sure this would work), or by using a key prefix. It would be the easiest I suppose, but doesn't seem ideal.
I guess what I really want is a way to group the cache items together, but for them to remain cache item. Something like a sub-cache I suppose.
Can anyone suggest the best way forward?