Home > Backend Development > PHP Tutorial > php apc cache usage example

php apc cache usage example

WBOY
Release: 2016-07-25 08:55:15
Original
830 people have browsed it
  1. defaults('ADMIN_USERNAME','apc'); // Admin Username
  2. defaults('ADMIN_PASSWORD','password'); // Admin Password - CHANGE THIS TO ENABLE!!!
Copy code

3. apc usage example APC is very simple to use. See the following examples of adding, querying, modifying, and deleting. 1), add a cache, the effective time is 3600 seconds apc_add('name', 'tom', 3600); Execute the code, and then check the User Cache Entries. You can see that there is an additional cache data with the key value name: php apc缓存 Among them are the number of hits, size, expiration time, etc. 2) Query cache

  1. apc_add('name', 'tom', 3600);
  2. print apc_fetch('name'); //Output tom
Copy code

3), modify cache

  1. apc_store('name', 'anny', 3600);
  2. print apc_fetch('name'); //Output anny
Copy code

4), delete cache

  1. apc_delete('name');
  2. var_dump(apc_fetch('name')); //Output bool(false)
Copy code

5), increasing and decreasing numbers If the cached content is a number, you can use apc_ inc to increase by 1 and apc_dec to decrease by 1.

  1. apc_add('num', 10);
  2. apc_inc('num');
  3. print apc_fetch('num');//Output 11
  4. apc_dec('num');
  5. print apc_fetch('num ');//Output 10
Copy code

6), determine whether the cache exists

  1. apc_add('name', 'tom', 3600);
  2. var_dump(apc_exists('name')); //Output bool(true)
  3. var_dump(apc_exists('age')); // bool(false)
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template