Phpmemecache cache Group

Source: Internet
Author: User
The phpmemecache cache group is confused in the phpmemcache cache. I only find the add and delete methods to add or delete caches. The group function is not available. for example, memecache for JAVA has the group function, if I use a user diary group, when I update the diary, I can delete this diary group cache, my personal diary list, my WAP version's diary list is also updated. I have questions about how to use the ad php memecache cache group function.
In the php memcache cache, I only find add and delete methods to add or delete the cache. no group function is available.

For example, memecache of JAVA has the grouping function. if I use a user's diary group, when I update a diary, I can delete this diary group cache, my personal diary list, my WAP diary list is also updated

What functions do I have?

Add ("cacheGroup", "cacheName1", $ value1 );
Add ("cacheGroup", "cacheName2", $ value2 );
Add ("cacheGroup", "cacheName3", $ value3 );
DeleteGroup ("cacheGroup ");
Then all the above three caches are cleared.




The php memecache cache API is as follows:
Memcache: add-add a value. if it already exists, false is returned.
Memcache: addServer-add an available server address
Memcache: close-close a Memcache object
Memcache: connect-create a Memcache object
Memcache_debug-control debugging function
Memcache: decrement-deletes the value of a saved key.
Memcache: delete-delete a key value
Memcache: flush-clear all cached data
Memcache: get-get a key value
Memcache: getExtendedStats-obtains the running system statistics of all processes in the process pool.
Memcache: getServerStatus-get the parameters of the running server
Memcache: getStats-return some running statistics of the server
Memcache: getVersion-returns the version information of the running Memcache.
Memcache: increment-adds the value of a saved key.
Memcache: pconnect-creates a persistent connection object for Memcache.
Memcache: replace-R: overwrites an existing key.
Memcache: set-add a value. if it already exists, overwrite it.
Memcache: setCompressThreshold-compresses data larger than a certain size
Memcache: setServerParams-modify server parameters at runtime

------ Solution --------------------
Add ("cacheGroup", "cacheName1", $ value1 );
Add ("cacheGroup", "cacheName2", $ value2 );
Add ("cacheGroup", "cacheName3", $ value3 );
DeleteGroup ("cacheGroup ");

This means that a key controls an array.
PHP code
Class mem {public $ memcache = null; public $ array = array (); public function _ construct () {$ this-> memcache = new Memcache; $ this-> memcache-> connect ('localhost', 11211) or die ("cocould not connect");} public function add ($ parent = "", $ key = "", $ value = "") {$ this-> array [$ key] = $ value; $ this-> memcache-> set ($ parent, $ this-> array, false, 500);} public function deleteGroup ($ key = null) {$ this-> memcache-> delete ($ key );} public function get ($ key = null) {return $ this-> memcache-> get ($ key) ;}}$ mem = new mem (); $ mem-> add ("cacheGroup", "cacheName1", "1"); $ mem-> add ("cacheGroup", "cacheName2", "2 "); $ mem-> add ("cacheGroup", "cacheName3", "3"); // $ mem-> deleteGroup ("cacheGroup "); var_Dump ($ mem-> get ('cachegroup '));
------ Solution --------------------

Discussion

1,
You use parent: set ($ group, $ expire) in setGroupExpire; isn't that about adding a cache? How does it set the cache time?

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.