I believe that everyone is not unfamiliar with the memcache, in the project also often use memcache as a caching scheme, then in the use of the process has not found why Memcahce has two ways to add caching: One is Add, one is set, then you know how these 2 methods are different. When you should use Add. When should you use set?
To this point, I did not go into the deep, only know to add the cache with set on it, as if most of the use of the Set method, and add seems to be very rarely used. A few days ago and a friend to talk about this, tonight here to record the difference between the 2 methods.
1, Memcache::add Method: The Add method is used to add a data to the Memcache server to be cached.
Note: The Add method call fails if the key to be stored already exists in the Memcache server.
2. Memcache::set method: The Set method is used to set the cached content of a specified key, and the Set method is the collection of the Add method and the Replace method.
Attention:
1, if the key to be set does not exist, then the set method and the Add method of the same effect;
2, the Set method works the same as the Replace method if the key you want to set already exists.
As with the add and set methods on parameters, there is no explanation here.
How to know the difference between the two methods of memcache add and set, you can pay attention to later use.