stefangabos/zebra_cache

一个基于文件的轻量级PHP缓存库,使用文件锁来确保在高负载下的正常功能

1.3.2 2023-01-03 21:59 UTC

This package is auto-updated.

Last update: 2024-09-18 19:23:38 UTC


README

zebra-curl-logo

Zebra Cache  Tweet

一个基于文件的轻量级PHP缓存库,使用文件锁来确保在高负载下的正常功能。

Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License

功能

  • 使用文件锁来确保在高负载下的正常功能 - 也就是说,在并发环境中,写入缓存文件的写入将获得文件的独占锁,读取将在获取缓存数据之前等待写入完成
  • 自动序列化和压缩缓存数据以节省空间并提高性能
  • 基于指定的存活时间(TTL)值自动过期缓存项
  • 支持多个实例,允许您为应用程序的不同部分使用不同的缓存配置

📔 文档

查看出色的文档

🎂 支持本项目的发展

您的支持非常受赞赏,它让我有动力继续从事开源项目。如果您喜欢这个项目,请点击页面顶部的星星按钮给它加星。如果您愿意,也可以通过PayPal购买我一杯咖啡或成为赞助者。感谢您的支持! 🎉

Star it on GitHub Donate

要求

PHP 5.3.0+

安装

您可以通过 Composer 安装

# get the latest stable release
composer require stefangabos/zebra_cache

# get the latest commit
composer require stefangabos/zebra_cache:dev-master

或者您可以通过下载最新版本,解压缩,然后将其包含到您的项目中手动安装

require_once 'path/to/Zebra_Cache.php';

如何使用

// instantiate the library
$cache = new Zebra_Cache('path/to/store/cache-files/');

// if a cached, non-expired value for the sought key does not exist
if (!($some_data = $cache->get('my-key'))) {

    // do whatever you need to retrieve data
    $some_data = 'get this data';

    // cache the values for one hour (3600 seconds)
    $cache->set('my-key', $some_data, 3600);

}

// $some_data now holds the values, either fresh or from cache

获取缓存数据信息

if ($cached_info = $cache->has('my-key')) {

    // will output something in the  likes of
    //  Array (
    //    'path'     => '',  //  path to the cache file
    //    'timeout'  => '',  //  the number of seconds the cache was supposed to be valid
    //    'ttl'      => '',  //  number of seconds remaining until the cache expires
    //  )

    print_r('<pre>');
    print_r($cached_info);

}

删除缓存数据

$cache->delete('my-key');