fu-hsi/file-cache

FileCache 类

dev-master 2015-01-16 18:15 UTC

This package is auto-updated.

Last update: 2024-09-17 02:05:35 UTC


README

FileCache 类可以缓存您的 Web 服务响应结果、渲染的模板、SQL 结果集等。提供三种序列化变量的方式。

用法

<?php
use FuHsi\FileCache\FileCache;
require '../FileCache/FileCache.php';

$options = array(
    'cacheDir' => __DIR__,
    'lifeTime' => FileCache::HOUR,
    'format' => FileCache::FORMAT_VAR_EXPORT
);
$cache = new FileCache($options);

$result = $cache->get('my unique key', true, function ()
{
    return array(
        1,
        2,
        3,
        4,
        5
    );
});

var_dump($result);
?>

提示

在不实例化 FileCache 类的情况下,从缓存文件中读取序列化数据。

$fromCache = include 'cached-data.php';