snapflowio/cache
最新稳定版本:v0.1.0
Composer 安装命令:
composer require snapflowio/cache
包简介
A simple and lightweight library caching data to multiple sources.
README 文档
README
A simple and lightweight library caching data to multiple sources.
Installation
composer require snapflow/cache
Quick Start
<?php use Snapflow\Cache\Cache; use Snapflow\Cache\Adapter\Memory; use Snapflow\Cache\Adapter\Redis; // Create cache instance with Memory adapter $cache = new Cache(new Memory()); // Save data to cache $cache->save('user:123', ['name' => 'John Doe', 'email' => 'john@example.com']); // Load from cache (TTL: 3600 seconds) $user = $cache->load('user:123', 3600); // Remember pattern: get from cache or execute callback $data = $cache->remember('expensive:query', 3600, function() { // This only runs if cache is empty return fetchExpensiveData(); }); // Batch operations $cache->saveMultiple([ 'user:1' => $user1, 'user:2' => $user2, 'user:3' => $user3, ]); $users = $cache->loadMultiple(['user:1', 'user:2', 'user:3'], 3600); // Atomic counters $cache->increment('page:views'); $views = $cache->increment('api:requests:' . $ip, 5); // Using Redis adapter $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $redisCache = new Cache(new \Snapflow\Cache\Adapter\Redis($redis)); // Tags support use Snapflow\Cache\TaggableCache; $cache = new TaggableCache(new Memory()); $cache->saveWithTags('post:1', $postData, ['posts', 'author:john'], 3600); $cache->flushByTag('author:john'); // Remove all posts by author
License
This library is available under the MIT License.
Copyright
Copyright (c) 2025 Snapflow
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-16