元缓存或Codeigniter缓存
问题描述:
我应该使用哪个缓存减少页面的加载时间 - Meta Cache或Codeigniter Caching。
Which cache should i make use to reduce the loading time of a page - Meta Cache or Codeigniter Caching.
请建议。
答
藏; http://code.google.com/p/stash/ ,在工作,这是伟大的。它使用一个层次化的关键字结构,这对于缓存相关的项目是非常有用的。
I recently used Stash; http://code.google.com/p/stash/, at work and it's great. It uses a hierarchical key structure which is really useful for caching related items.
我使用这个库文件将其作为第三方软件包进行集成。我去了。
I used this library file to integrate it as a third party package and away I went.
<?php
class Stash {
private $_pool;
public function __construct($options)
{
include_once APPPATH . '/third_party/Stash/autoload.php';
if (isset($options['stash']) && isset($options['stash']['path'])) {
if (substr($options['stash']['path'], 0, 1) != '/') {
$options['stash']['path'] = getcwd() . '/' . $options['stash']['path'];
}
}
$handler = new Stash\Handler\FileSystem(@$options['stash']);
$this->_pool = new Stash\Pool;
$this->_pool->setHandler($handler);
}
public function getCache($path)
{
return $this->_pool->getCache($path);
}
}
?>
只需使用这个简单的配置文件:
Just use this simple config file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| Stash Cache settings
| -------------------------------------------------------------------
|
*/
$config['stash'] = array('path' => APPPATH .'/cache');
然后你可以这样使用:
$this->load->library('Stash');
$cache = $this->stash->getCache(array('key1','subkey1','subkey2'));
$cache->set('foo', 'bar', 30);