0

I have following large object (20KB) cached in memcache -

Product : 
{
    BasicInfo, //~5KB
    SellerId,  //int
    CityId,    //int
    AdditionalInfo //~15KB
}

This is being accessed at multiple places-

  1. At some place, only sellerId or cityId is required.
  2. At some places, only basicInfo is required.
  3. At some places, whole object is required.

So we are fetching whole object unnecessarily in 1st and 2nd cases while we only require some bytes. Should I store these separately in memcache (only problem is I need to invalidate multiple keys on updation)?

Is there any better way to handle these cases?

ctor
  • 101
  • 2

1 Answers1

1

Since it's a cache, the best is definitively to store it in one place.

Ensuring cache integrety is already hard enough to do properly in large application to add more complexity.

The only problem you could run into is to use different criteria of search to retrieve the same object depending of the current use case. In this case you could need differents caches to handle the different kind of search criteria.

Walfrat
  • 3,456
  • 13
  • 26
  • So you are saying we have to create duplicate caches for requirement of accessing only sellerId? – ctor Aug 02 '17 at 09:25
  • No, I'am saying that if you have different criteria to search for the object from the cache (like retrieve once by CityId, another time by SellerId) you will need different caches). If you always retrieves by for instance CityId, then you need only one cache with the full object. – Walfrat Aug 02 '17 at 09:30