ark/filecache

基于文件系统的缓存

v0.1.0 2015-03-22 07:32 UTC

This package is auto-updated.

Last update: 2024-09-13 21:51:11 UTC


README

基于文件系统的缓存。

为什么使用文件缓存?

当您不想添加其他依赖项或者不想浪费您的RAM时。

特性

  • 使用 gzcompress 进行压缩
  • 过期
  • 多级缓存目录

安装

composer require ark/filecache

使用方法

<?php
use Ark\Filecache\FileCache;

$cache = new FileCache([
    'root' => '/path/to/cache/root', // Cache root
    'ttl' => 0,                    // Time to live
    'compress' => false,             // Compress data with gzcompress or not
    'serialize' => 'json',          // How to serialize data: json, php, raw
]);

$cache->set('key1', 'value1');
$cache->get('key1');

// Set TTL and compression
$cache->set('key2', array('hello', 'world'), array(
    'ttl' => 10,
    'compress' => true
)); 

sleep(11);

$cache->get('key2');

$cache->delete('key1');

$cache->clear(); // clear all caches by removing the root path of the cache