首页 > 代码库 > Cache
Cache
大致的调用方法请参考 AUTH模块
缓存最简单的是文件缓存:
举个最简单的例子:
先配置好cache 配置文件:
1 <?php defined(‘SYSPATH‘) or die(‘No direct script access.‘); 2 return array 3 ( 4 ‘memcache‘ => array( 5 ‘driver‘ => ‘memcache‘, 6 ‘default_expire‘ => 3600, 7 ‘compression‘ => FALSE, // Use Zlib compression (can cause issues with integers) 8 ‘servers‘ => array( 9 ‘local‘ => array(10 ‘host‘ => ‘localhost‘, // Memcache Server11 ‘port‘ => 11211, // Memcache port number12 ‘persistent‘ => FALSE, // Persistent connection13 ‘weight‘ => 1,14 ‘timeout‘ => 1,15 ‘retry_interval‘ => 15,16 ‘status‘ => TRUE,17 ),18 ),19 ‘instant_death‘ => TRUE, // Take server offline immediately on first fail (no retry)20 ),21 ‘memcachetag‘ => array(22 ‘driver‘ => ‘memcachetag‘,23 ‘default_expire‘ => 3600,24 ‘compression‘ => FALSE, // Use Zlib compression (can cause issues with integers)25 ‘servers‘ => array(26 ‘local‘ => array(27 ‘host‘ => ‘localhost‘, // Memcache Server28 ‘port‘ => 11211, // Memcache port number29 ‘persistent‘ => FALSE, // Persistent connection30 ‘weight‘ => 1,31 ‘timeout‘ => 1,32 ‘retry_interval‘ => 15,33 ‘status‘ => TRUE,34 ),35 ),36 ‘instant_death‘ => TRUE,37 ),38 ‘apc‘ => array(39 ‘driver‘ => ‘apc‘,40 ‘default_expire‘ => 3600,41 ),42 ‘wincache‘ => array(43 ‘driver‘ => ‘wincache‘,44 ‘default_expire‘ => 3600,45 ),46 ‘sqlite‘ => array(47 ‘driver‘ => ‘sqlite‘,48 ‘default_expire‘ => 3600,49 ‘database‘ => APPPATH.‘cache/kohana-cache.sql3‘,50 ‘schema‘ => ‘CREATE TABLE caches(id VARCHAR(127) PRIMARY KEY, tags VARCHAR(255), expiration INTEGER, cache TEXT)‘,51 ),52 ‘eaccelerator‘ => array(53 ‘driver‘ => ‘eaccelerator‘,54 ),55 ‘xcache‘ => array(56 ‘driver‘ => ‘xcache‘,57 ‘default_expire‘ => 3600,58 ),59 ‘file‘ => array(60 ‘driver‘ => ‘file‘,61 ‘cache_dir‘ => APPPATH.‘cache‘,62 ‘default_expire‘ => 3600,63 ‘ignore_on_delete‘ => array(64 ‘.gitignore‘,65 ‘.git‘,66 ‘.svn‘67 )68 )69 );
然后
1 $cache=Cache::instance(‘file‘); 2 $arr=array(1,2,3,4,51,2,3,3,6,8,9,0);3 //$cache->set(1,$arr); //添加缓存;4 print_r($cache->get(1)); //获取缓存;
将数据存储到sqlite中:
首先确保你的系统有没有安装sqlite3和 php-sqlite,如果没有 apt-get安装并重启apache。
使用方法和文件一样,只有初始化方法不同:
$cache=Cache::instance(‘sqlite‘);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。