The difference between add and set methods in Memcache

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.