Check if a key exists in Memcache

前端 未结 11 2333
无人共我
无人共我 2021-02-12 15:17

How do I check in PHP if a value is stored in Memcache without fetching it? I don\'t like fetching it because the values I have set are all 1MB in size and after I fetch it, I h

11条回答
  •  爱一瞬间的悲伤
    2021-02-12 15:41

    Basically what you want to do is to fill memcached with your data, right?

    The thing is that asking if a key is there withouth retrieving the value is not very useful. See this case scenario:

    You ask if a key exists and it does. Just after you ask, the data of the key is expelled from the cache. While your response is coming back saying that the date is there, the reality is that the data is not there. So you lost time asking, because the answer is different from reality.

    I guess what you want to do is to ask if a key exists, and then if it does not, fill it with your data. Why don't you fill directly all the data? Btw, have you considered that while you are filling memcached with data, you could be expelling keys you just previously inserted?

提交回复
热议问题