em4nl/ucache

简单、基于文件系统的html(/xml/json/...)缓存

v0.0.4 2019-03-08 09:28 UTC

This package is auto-updated.

Last update: 2024-09-08 22:58:50 UTC


README

简单、基于文件系统的html(/xml/json/...)缓存

安装

通过composer

composer require em4nl/ucache

使用方法

假设您正在使用自动加载,并且您的composer vendor目录位于./vendor

<?php

require_once __DIR__ . '/vendor/autoload.php';

$cache = new Em4nl\U\Cache(__DIR__ . '/cache');

// not mandatory: register cache invalidation function
$cache->invalidate(function($filename) {
    // don't serve files from cache that are older than 3 hours
    // (returning TRUE here means TO INVALIDATE, returning false
    // or nothing means the file remains in the cache!)
    return filemtime($filename) < time() - 60 * 60 * 3;
});

// try to serve from cache; if that fails, create the output and
// cache it for next time
if (!$cache->serve()) {
    $cache->start();
    echo 'Hello World';
    $cache->end();
}

开发

安装依赖项

composer install

运行测试

./vendor/bin/phpunit tests

许可证

MIT许可证