开发者

PHP Cache System for remote JSON/XML request

i need to caching xml and json response requested to a re开发者_运维问答mote host. Is There a simple Cache System developed in PHP?


If you are looking to get up and running right away, you can use APC, which is installed (or can be easily installed) with PHP, depending on what platform you are running PHP on. Then you can use the apc_add() function call to add keys into the cache.

Example:

<?php
   $bar = 'BAR';
   apc_add('foo', $bar);
?>

You can then use apc_exists() and apc_fetch() to check and fetch items out of the cache.

Obviously if your requirements are more complex, you may want to take a look at Memcached


PHP itself can't cache because it is interpreted at request time - there isn't any in-memory caching capabilities naively available. If you have control over the web server, you may be able to install APC cache. see this for a little info on how to use API. If not, you can check if that extension is installed (in my experience, not may hosts have this installed), ask for it to be installed, or simply grow your own (see below).

APC cache is a simple file-based caching mechanism that provides some neat facilities to expunge caches that grow old. You can build this yourself using the standard PHP library if APC isn't available (or you're doing something really simple). If you have to roll your own, use the above like as an implementation guide - build in the features you need and leave out what you don't. =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜