What is the difference between Memcache store () and add ()?

I am wondering what is the difference between store () and add ()? They seem very similar, however I notice that adding only adds an element if it does not exist. Did the installed item already exist?

+4
source share
2 answers

Set will install it or reset, regardless of whether it exists. Add will add it only if it does not exist. This will help if you have something that cannot be obtained from the cache, and then 1000 people make the same request and everyone is trying to install it at the same time.

+3
source

Not sure which api calls you use, but if both of them specify some object with a key / value, the behavior should only differ if the key already exists. add will error, and the save (or rather set) will be replaced.

0
source

Source: https://habr.com/ru/post/1403168/


All Articles