mlevent/file-cache

PHP的简单文件类型缓存包。

v0.1.0 2023-08-29 02:10 UTC

This package is auto-updated.

Last update: 2024-09-29 06:26:00 UTC


README

PHP的简单、文件类型缓存类。

安装

🛠️ 使用composer将包添加到项目中;

composer require mlevent/file-cache

示例用法

use Mlevent\FileCache\FileCache;

$cache = new FileCache;

$updatedTime = $cache->refresh('updatedTime', function () {
    return date("H:i:s");
}, 60);

echo "Updated time: {$updatedTime}";

默认情况下,缓存文件存储在./cache目录中;

$ tree ./cache
./cache
└── f7
    └── d1
        └── 7411a1eeb3dabcc2311f04eeb5371f0f40f192f3.cache

以下是一个传统用法的示例;

use Mlevent\FileCache\FileCache;

// Önbellek dosyaları ./cache dizininde saklanacak
$cache = new FileCache('./cache');

// Geçerlilik süresi dolduysa
if ($cache->isExpired('updatedTime')) {

    // Geçerlilik süresini 60 saniye daha uzat ve yeni veriyi yaz
    $cache->put('updatedTime', date("H:i:s"), 60);
}

// Veriyi önbellekten oku
$updatedTime = $cache->get('updatedTime');

echo "Updated time: {$updatedTime}";
/**
 * @return bool
 */
$cache->has(string $name);

/**
 * @return bool
 */
$cache->delete(string $name);

/**
 * @return void
 */
$cache->flush();

/**
 * @return array
 */
$cache->getStore();

📧联系

发送电子邮件至ghergedan@gmail.com进行联系。