app-skeleton / cache
官方的 Kohana 缓存管理模块
v3.3.1
2013-08-26 02:05 UTC
Requires
- php: >=5.3.3
- composer/installers: ~1.0
- kohana/core: >=3.3
This package is not auto-updated.
Last update: 2024-09-24 06:51:47 UTC
README
Kohana 3 缓存库提供了一个简单的接口,用于最常用的缓存解决方案。开发者可以自由添加符合此模块内定义的缓存设计模式的自定义缓存解决方案。
支持的缓存解决方案
目前此模块支持以下缓存方法。
- APC
- Memcache
- Memcached-tags(支持标签)
- SQLite(支持标签)
- 文件
- Wincache
计划支持的
在不久的将来,将包括对以下方法的额外支持。
- Memcached
缓存介绍
为了最大限度地利用缓存,您的应用程序应该从一开始就考虑缓存。通常,最有效的缓存包含大量的小数据集,这些数据集是昂贵计算操作的结果,例如在大数据集中进行搜索。
PHP有多种不同的缓存方法可供选择,从非常基本的基于文件的缓存到 eAccelerator 和 APC 中的代码缓存。使用物理内存而不是基于磁盘存储的缓存引擎通常更快,但许多不支持更高级的功能,如标签。
使用缓存
要使用 Kohana Cache,请从Github下载并解压 Kohana Cache 的最新稳定版本。将模块放置在您的 Kohana 实例模块文件夹中。最后,在应用程序引导中的“模块”部分启用模块。
快速示例
以下是如何使用 Kohana Cache 的快速示例。示例使用 SQLite 驱动程序。
<?php
// Get a Sqlite Cache instance
$mycache = Cache::instance('sqlite');
// Create some data
$data = array('foo' => 'bar', 'apples' => 'pear', 'BDFL' => 'Shadowhand');
// Save the data to cache, with an id of test_id and a lifetime of 10 minutes
$mycache->set('test_id', $data, 600);
// Retrieve the data from cache
$retrieved_data = $mycache->get('test_id');
// Remove the cache item
$mycache->delete('test_id');
// Clear the cache of all stored items
$mycache->delete_all();