district5/cache-lib 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

district5/cache-lib

最新稳定版本:2.0.0

Composer 安装命令:

composer require district5/cache-lib

包简介

Cache lib is a caching library for PHP

关键字:

README 文档

README

CacheLib is a flexible caching library for PHP.

Using Composer

Example Composer file contents:

composer require district5/cache-lib

Testing

Tests against adapters will only occur if the extension is loaded (for example APC/Memcache/Memcached).

$ composer install

$ ./vendor/bin/phpunit

Quick Start

CacheLib exposes the following methods for Caching:

  • APC / APCU - The
  • Memcache
  • Memcached
  • FileSystem

To find out more about how to use the adapters, see the tests/CacheLibTests/Adapters directory.

In addition to this, there is a AdapterNull which you can use for test (or development) purposes.

APC Adapter

The APC adapter will either use apc or apcu depending on availability.

<?php
$key = 'name';
$value = 'Joe Bloggs';

$adapter = new \District5\CacheLib\Adapters\AdapterApc(
    [
        'prefix' => '' // default
    ]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool

FileSystem Adapter

The APC adapter will either use apc or apcu depending on availability.

<?php
$key = 'name';
$value = 'Joe Bloggs';

$adapter = new \District5\CacheLib\Adapters\AdapterFileSystem(
    [
        'prefix' => '', // optional
        'path' => '/some/writable/directory'
    ]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool

Memcache Adapter

The memcache adapter supports multiple memcache servers like the memcached adapter

<?php
$key = 'name';
$value = 'Joe Bloggs';

$adapter = new \District5\CacheLib\Adapters\AdapterMemcache(
    [
        'prefix' => '', // optional
        'servers' => [
            [
                'host' => 'a-host-name',
                'port' => 11211,
                'timeout' => 60,
                'weight' => 1
            ],
            [
                'host' => 'another-host-name',
                'port' => 11211,
                'timeout' => 60,
                'weight' => 1
            ]
        ]
            
    ]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool

Memcached Adapter

The memcached adapter supports multiple servers, like the memcache adapter.

<?php
$key = 'name';
$value = 'Joe Bloggs';

$adapter = new \District5\CacheLib\Adapters\AdapterMemcached(
    [
        'prefix' => '', // optional
        'persistent_id' => '', // optional
        'servers' => [
            [
                'host' => 'a-host-name',
                'port' => 11211,
                'weight' => 1
            ],
            [
                'host' => 'another-host-name',
                'port' => 11211,
                'weight' => 1
            ]
        ]
            
    ]
);
$adapter->get($key, $default = null); // returns false or mixed
$adapter->set($key, $value, $ttl = 86400); // returns bool
$adapter->has($key); // returns bool
$adapter->renew($key, $ttl); // returns bool
$adapter->remove($key); // returns bool
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns bool
$adapter->flush(); // returns bool

Null Adapter (for tests)

The null adapter returns false for all methods. It's useful for some test cases.

<?php
$key = 'name';
$value = 'Joe Bloggs';

$adapter = new \District5\CacheLib\Adapters\AdapterNull([]);
$adapter->get($key, $default = null); // returns false
$adapter->set($key, $value, $ttl = 86400); // returns false
$adapter->has($key); // returns false
$adapter->renew($key, $ttl); // returns false
$adapter->remove($key); // returns false
$adapter->setIfNotExists($key, $value, $ttl = 86400); // returns false
$adapter->flush(); // returns false

Getting APCU working on a Mac

$ pecl install apcu

Add this to your php.ini file (/usr/local/etc/php/7.4/php.ini)

apc.enabled=on
apc.shm_size=64M
apc.enable_cli=on

统计信息

  • 总下载量: 94
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-18