Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: apc_store - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net

search for in the

APD" width="11" height="7"/> <apc_sma_info
Last updated: Wed, 01 Nov 2006
view this page in

apc_store

(PECL)

apc_store --  変数をデータ領域にキャッシュする

説明

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

注意: PHP の他の多くの仕組みと異なり、apc_store() を用いて格納された変数はリクエストを超えて (その値がキャッシュから取り除かれるまで)持続します。

パラメータ

key

この名前を用いて変数を格納します。key は キャッシュ内で一意です。そのため、同一の key で新しい値を格納すると、元の値は上書きされます。

var

格納する変数。

ttl

有効期間。var は、キャッシュに ttl 秒間だけ格納されます。 ttl が経過すると、格納されている変数は (次のリクエスト時に)キャッシュから削除されます。 ttl が指定されていない(あるいは ttl0 の場合)は、 キャッシュから手動で削除される・あるいはキャッシュに存在できなくなる (clear, restart など)まで値が持続します。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例 1. A apc_store() の例

<?php
$bar
= 'BAR';
apc_store('foo', $bar);
var_dump(apc_fetch('foo'));
?>

上の例の出力は以下となります。

string(3) "BAR"



add a note add a note User Contributed Notes
apc_store
php at tequilasolutions dot com
03-Nov-2006 08:45
Seems to be no (easy) way at the to know how old a value fetched is and to check whether it is out of date.

I've made these wrappers so that you can fetch and store values based on a udt returned from get_last_modified_date() which should return a udt of when your data was last changed, and hence needs junking out of the cache.

function apc_fetch_udt($key){
   $g = apc_fetch($key);
   if ($g){
       list($udt,$val) = $g;
       if (get_last_modified_date()<$udt) {
           $val = unserialize($val);
           return $val;
       } else {
           apc_delete($key);
       }
   }
}
function apc_store_udt($key,$g){
   $udt = time();
   $g  = serialize($g);
   $apc = array($udt,$g);
   apc_store($key, $apc);
}
Sudhee
30-Oct-2006 09:09
It should be noted that apc_store appears to only store one level deep.  So if you have an array of arrays, and you store it.  When you pull it back out with apc_fetch it will only have the top level row of keys with nulls as the values of each key.
 
Solution to this, is to serialize the data before storing it in the cache and unserialize it while retrieving from the cache.
php at metalshard dot com
29-Oct-2006 02:48
It should be noted that apc_store appears to only store one level deep.  So if you have an array of arrays, and you store it.  When you pull it back out with apc_fetch it will only have the top level row of keys with nulls as the values of each key.

APD" width="11" height="7"/> <apc_sma_info
Last updated: Wed, 01 Nov 2006
 
 
show source | credits | sitemap | contact | advertising | mirror sites