承接 initphp/cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

initphp/cache

最新稳定版本:1.0.0

Composer 安装命令:

composer require initphp/cache

包简介

A lightweight PSR-16 (Simple Cache) implementation with file, PDO, Redis, Memcache(d) and WinCache handlers.

README 文档

README

A lightweight PSR-16 (Simple Cache) implementation with interchangeable handlers for the filesystem, PDO databases, Redis, Memcache(d) and WinCache.

CI Latest Stable Version Total Downloads License PHP Version Require

Requirements

Each handler may need its own PHP extension:

Handler Class Backend Needs
File InitPHP\Cache\Handler\File Filesystem — (core only)
PDO InitPHP\Cache\Handler\PDO SQL database (MySQL, SQLite, PostgreSQL…) ext-pdo
Redis InitPHP\Cache\Handler\Redis Redis ext-redis (phpredis)
Memcache InitPHP\Cache\Handler\Memcache Memcached ext-memcached or ext-memcache
WinCache InitPHP\Cache\Handler\Wincache WinCache user cache ext-wincachedeprecated

Installation

composer require initphp/cache

Quick start

require 'vendor/autoload.php';

use InitPHP\Cache\Cache;
use InitPHP\Cache\Handler\File;

$cache = Cache::create(File::class, [
    'path' => __DIR__ . '/var/cache',
]);

// Read-through pattern: compute and store on a miss.
$posts = $cache->get('posts');
if ($posts === null) {
    $posts = [
        ['id' => 12, 'title' => 'Post 12'],
        ['id' => 15, 'title' => 'Post 15'],
    ];
    $cache->set('posts', $posts, 120); // cache for 120 seconds
}

print_r($posts);

Cache::create() returns a handler that implements InitPHP\Cache\CacheInterface, which extends Psr\SimpleCache\CacheInterface. You can equally type-hint and pass any PSR-16 cache around your application.

Switching handlers

Only the factory call changes; the cache API is identical for every backend.

use InitPHP\Cache\Cache;
use InitPHP\Cache\Handler\Redis;

$cache = Cache::create(Redis::class, [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
]);

$cache->set('user:42', ['name' => 'Jane'], 3600);
$cache->get('user:42');

API at a glance

Call Returns Purpose
get(string $key, mixed $default = null) mixed Read a value, or $default on a miss.
set(string $key, mixed $value, null|int|DateInterval $ttl = null) bool Store a value, optionally with a TTL.
delete(string $key) bool Remove one item.
clear() bool Remove every item this handler owns.
has(string $key) bool Whether a live item exists.
getMultiple(iterable $keys, mixed $default = null) iterable Read many items at once.
setMultiple(iterable $values, null|int|DateInterval $ttl = null) bool Store many items at once.
deleteMultiple(iterable $keys) bool Remove many items at once.
increment(string $key, int $offset = 1) int Add to a counter and return the new value.
decrement(string $key, int $offset = 1) int Subtract from a counter and return the new value.

See docs/ for the full guide, including per-handler configuration and the exact semantics of TTLs, keys and counters.

Notes

  • TTL: null means "store with no expiry"; a positive integer or DateInterval sets a lifetime; a zero or negative TTL deletes the item.
  • Keys: any non-empty string that does not contain the PSR-16 reserved characters {}()/\@:. An invalid key throws an InvalidArgumentException.
  • Counters: increment()/decrement() treat a missing or non-numeric item as 0 and store the result without an expiry. They behave identically across every handler.
  • Values: anything serialize() can handle round-trips exactly — including null, false and objects.

Documentation

Contributing

Bug reports and pull requests are welcome. CI runs PHP-CS-Fixer, PHPStan (max level) and PHPUnit across PHP 8.0–8.4, plus a Redis/Memcached integration job. Run the same static bundle locally with:

composer ci

See the changelog for release history.

Credits

License

Copyright © 2022 InitPHP — released under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固