sharnw/filecached-php

此包的最新版本(dev-master)没有可用的许可证信息。

使用文件系统而不是内存的简单PHP键值存储

dev-master 2016-12-07 04:00 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:22:30 UTC


README

使用文件系统而不是内存的简单键值存储。

适用于缓存大型数据集,以及替换低内存AWS实例上的memcache。

归功于https://github.com/hustcc提供的原始版本。

安装

将以下行添加到您的composer.json文件中

{
    "require": {
        "sharnw/filecached-php": "dev-master"
    }
}

使用

与memcache相似的接口

  • set(k, v) 设置键值对
  • get(k) 获取键值,如果没有内容则返回false
  • delete(k) 删除键值对
  • flush() 删除所有缓存数据

演示

require_once('src/cache.php');

$cache = new Filecached\Cache();

$example_data = [
    'time' => time(),
    'message' => 'something certainly happened today.',
];

$cache->set('todays_news', $example_data);

print_r($storeData = $cache->get('todays_news'));

$example_data = [
    [
        'url' => 'https://libraries.io/github/hustcc/php-file-cache',
        'title' => 'Forked repo'
    ],
];

$cache->set('todays_links', $example_data);

print_r($storeData = $cache->get('todays_links'));

$cache->flush('today_'); // flush all data in 'today/' namespace

$cache->set('more data', ['blah']);

$cache->flush(); // flush all data

许可证

MIT许可证的条款下发布。

链接