gilbitron/hoard

PHP缓存,做到正确

0.1.1 2015-01-07 17:26 UTC

This package is auto-updated.

Last update: 2024-09-12 03:16:44 UTC


README

Build Status

Hoard是一个简单、可扩展的PHP缓存库。

安装

通过composer安装

{
    "require": {
        "gilbitron/hoard": "~0.1.0"
    }
}

运行composer install然后按常规使用

require 'vendor/autoload.php';
$cache = new Hoard\Hoard();

API

Hoard使用“抽屉”的概念(类似于抽屉柜)作为缓存的驱动程序。

$cache = new Hoard\Hoard($drawer = 'file', $options = [], $args = []);

可能的抽屉(更多即将到来)

  • 文件

$options是传递给所选抽屉的选项数组。请参阅下文的抽屉部分。

$args:

  • encrypt_keys - 使用加密键(默认:true
  • encryption_function - 用于加密键的函数md5/sha1(默认:md5

确定缓存中是否存在项目

$cache->has($key);

通过键从缓存中检索项目

$cache->get($key, $default = null);

从缓存中检索项目并将其删除

$cache->pull($key, $default = null);

在缓存中存储项目。 $minutes可以是一个整数或DateTime

$cache->put($key, $value, $minutes);

如果键不存在,则在缓存中存储项目。$minutes可以是一个整数或DateTime

$cache->add($key, $value, $minutes);

无限期地在缓存中存储项目

$cache->forever($key, $value);

从缓存中删除项目

$cache->forget($key);

从缓存中删除所有项目

$cache->flush();

抽屉

文件

基本的文件系统缓存。

选项

  • cache_dir - 缓存目录的路径。如果没有提供,则使用系统临时目录。

致谢

Hoard是由来自Gilbert PellegromDev7studios创建的。在MIT许可下发布。