store single big object in memcached vs multiple keys

孤者浪人 提交于 2019-12-11 05:37:52

问题


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?


回答1:


There are 2 aspects to consider here and the trade-off between them.

  1. Time to access cached data
  2. Consistency of data

How storing small granular data will reduce time to access i.e why complex object are taking more time?

  1. For storing any value in memcache, it has to be serialized and deserialized. The more complex the object is, it will add more processing for serialization and de-serialization @ application end.

  2. It is common in production to have memcache in a separate machine/s (same n/w or different n/w). In such cases, the bigger data size will add latency due to network i/o and roundtrip time.

It is a trade-off to use complete object or multiple granular objects.

In our case, where we use cache mostly for our cached data are high frequent read and rarely updated. We store granular level objects.



来源:https://stackoverflow.com/questions/45455922/store-single-big-object-in-memcached-vs-multiple-keys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!