PHP APC基本使用 (Alternative PHP Cache(可选PHP缓存))

来源:互联网 发布:多玩我的世界工业js 编辑:程序博客网 时间:2024/06/06 02:36

http://cn2.php.net/apc

官方手册中已经给你详细的说明

Alternative PHP Cache(可选PHP缓存)

  • 简介
  • 安装/配置
    • 需求
    • 安装
    • 运行时配置
    • 资源类型
  • 预定义常量
  • APC 函数
    • apc_add — 缓存一个变量到数据存储
    • apc_bin_dump — Get a binary dump of the given files and user variables
    • apc_bin_dumpfile — Output a binary dump of cached files and user variables to a file
    • apc_bin_load — Load a binary dump into the APC file/user cache
    • apc_bin_loadfile — Load a binary dump from a file into the APC file/user cache
    • apc_cache_info — Retrieves cached information from APC's data store
    • apc_cas — Updates an old value with a new value
    • apc_clear_cache — 清除APC缓存
    • apc_compile_file — Stores a file in the bytecode cache, bypassing all filters.
    • apc_dec — Decrease a stored number
    • apc_define_constants — Defines a set of constants for retrieval and mass-definition
    • apc_delete_file — Deletes files from the opcode cache
    • apc_delete — Removes a stored variable from the cache
    • apc_exists — 检查APC中是否存在某个或者某些key
    • apc_fetch — 从缓存中取出存储的变量
    • apc_inc — Increase a stored number
    • apc_load_constants — Loads a set of constants from the cache
    • apc_sma_info — Retrieves APC's Shared Memory Allocation information
    • apc_store — Cache a variable in the data store
  • APCIterator — The APCIterator class
    • APCIterator::__construct — Constructs an APCIterator iterator object
    • APCIterator::current — Get current item
    • APCIterator::getTotalCount — Get total count
    • APCIterator::getTotalHits — Get total cache hits
    • APCIterator::getTotalSize — Get total cache size
    • APCIterator::key — Get iterator key
    • APCIterator::next — Move pointer to next item
    • APCIterator::rewind — Rewinds iterator
    • APCIterator::valid — Checks if current position is valid
apc的tests文件中有简单的demos

例如

--TEST--
APC: apc_store/fetch with strings
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
apc.enabled=1
apc.enable_cli=1
apc.file_update_protection=0
--FILE--
<?php


$foo = 'hello world';
var_dump($foo);
apc_store('foo',$foo);
$bar = apc_fetch('foo');
var_dump($bar);
$bar = 'nice';
var_dump($bar);


apc_store('foo\x00bar', $foo);
$bar = apc_fetch('foo\x00bar');
var_dump($bar);


?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(11) "hello world"
string(11) "hello world"
string(4) "nice"
string(11) "hello world"
===DONE===


apc_store

bool apc_store ( string $key , mixed $var [, int $ttl = 0 ] )

apc_add

bool apc_add ( string $key , mixed $var [, int $ttl = 0 ] )

apc_fetch

mixed apc_fetch ( mixed $key [, bool &$success ] )

apc_delete

mixed apc_delete ( string $key )

apc_clear_cache

bool apc_clear_cache ([ string $cache_type ] )

apc_exists

mixed apc_exists ( mixed $keys )



程序逻辑就是上述函数的排列组合


原创粉丝点击