kohana/cache

官方 Kohana 缓存管理模块

安装数量: 302,566

依赖关系: 9

建议者: 0

安全性: 0

星标: 78

关注者: 15

分支: 79

类型:kohana-module

v3.3.6 2016-03-30 09:53 UTC

README

Kohana 3 缓存库提供了一个简单接口,用于最常见的缓存解决方案。开发者可以自由添加遵循此模块内定义的缓存设计模式的自己的缓存解决方案。

支持的缓存解决方案

目前此模块支持以下缓存方法。

  1. APC
  2. Memcache
  3. Memcached-tags(支持标签)
  4. SQLite(支持标签)
  5. 文件
  6. Wincache

计划支持

在不久的将来,将包括对以下方法的额外支持。

  1. Memcached

缓存介绍

为了最大限度地利用缓存,您的应用程序应该从一开始就考虑缓存设计。一般来说,最有效的缓存包含大量由昂贵的计算操作(如搜索大量数据集)生成的小数据集合。

PHP有很多不同的缓存方法可用,从非常基本的基于文件的缓存到 eAccelerator 和 APC 中的 opcode 缓存。使用物理内存而不是基于磁盘存储的缓存引擎总是更快,然而许多不支持更高级的功能,如标签。

使用缓存

要使用 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();