stefangabos/zebra_cache 问题修复 & 功能扩展

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

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

stefangabos/zebra_cache

Composer 安装命令:

composer require stefangabos/zebra_cache

包简介

A lightweight and flexible PHP caching library with support for file, Redis, and Memcached storage backends.

README 文档

README

Zebra Cache Logo

Zebra Cache  Tweet

A lightweight and flexible PHP caching library with support for file, Redis, and Memcached storage backends.

Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License

This library provides a unified interface for caching data, allowing the use of various storage backends like file-based caching, Redis, Memcached, or custom implementations.

It supports common caching operations such as storing, retrieving and deleting data, as well as checking for the existence of a cache entry.

Features

  • pluggable architecture for using different storage mechanisms
  • flexible key-value caching
  • automatic expiration of cache items based on a specified time-to-live (TTL) value
  • extensible design allowing developers to integrate new storage backends
  • easy-to-use API with consistent behavior across different backends
  • support for multiple instances, allowing you to use different cache configurations for different parts of your application

📔 Documentation

Check out the awesome documentation!

🎂 Support the development of this project

Your support is greatly appreciated and it keeps me motivated continue working on open source projects. If you enjoy this project please star it by clicking on the star button at the top of the page. If you're feeling generous, you can also buy me a coffee through PayPal or become a sponsor. Thank you for your support! 🎉

Star it on GitHub Donate

Requirements

PHP 7.0.0+

Use version 1.3.2 if you need support for PHP 5.3.0+

Installation

Install via Composer

# get the latest stable release
composer require stefangabos/zebra_cache

# get the latest commit
composer require stefangabos/zebra_cache:dev-master

Initializing the storage engine

Initializing file-based storage:

// make sure you have this at the top of your script
use stefangabos\Zebra_Cache\Zebra_Cache;
use stefangabos\Zebra_Cache\Storage\Storage_File;

// initialize file-based storage
$storage = new Storage_File('/path/to/cache/folder');

Initializing Redis-based storage:

// make sure you have this at the top of your script
use stefangabos\Zebra_Cache\Zebra_Cache;
use stefangabos\Zebra_Cache\Storage\Storage_Redis;

// connect to a Redis server
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

// pass the $redis instance as argument to initialize the Redis-based storage
$storage = new Storage_Redis($redis);

// finally, instantiate the caching library using the storage engine configured above
$cache = new stefangabos\Zebra_Cache\Zebra_Cache($storage);

Initializing Memcached-based storage:

There are two PHP extensions for working with Memcached: the memcache extension, which is older and less commonly used, and memcached which is generally preferred for better features and compatibility. This library supports both.

// make sure you have this at the top of your script
use stefangabos\Zebra_Cache\Zebra_Cache;
use stefangabos\Zebra_Cache\Storage\Storage_Memcached;

// connect to a Memcached server (using the `memcached` extension)
$memcache = new Memcached();
$memcache->addServer('localhost', 11211);

// OR using the `memcache` extension
$memcache = new Memcache();
$memcache->addServer('localhost', 11211);

// pass the $memcache instance as argument to initialize the Memcached-based storage
$storage = new Storage_Memcached($memcache);

Initializing the main library and setting/getting values

Once the storage engine is initialized:

// instantiate the caching library using the chosen storage engine
$cache = new Zebra_Cache($storage);

// if a cached, non-expired value for the sought key does not exist
if (!($my_data = $cache->get('my-key'))) {

    // do whatever you need to retrieve data
    $my_data = 'my data';

    // cache the values for 10 minutes (10 x 60 seconds)
    $cache->set('my-key', $my_data, 10 * 60);

}

// at this point $my_data will always contain data, either from cache, or fresh

Getting information about cached data

if ($info = $cache->has('my-key')) {

    print_r('<pre>');
    print_r($info);

    // for file-based storage the output will look something like
    // [
    //  'path'     => '',  //  path to the cache file
    //  'timeout'  => '',  //  the number of seconds the cache was supposed to be valid
    //  'ttl'      => '',  //  number of seconds remaining until the cache expires
    // ]

}

Deleting cached data

$cache->delete('my-key');

stefangabos/zebra_cache 适用场景与选型建议

stefangabos/zebra_cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「redis」 「performance」 「php」 「filesystem」 「memcache」 「cache」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 stefangabos/zebra_cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 stefangabos/zebra_cache 我们能提供哪些服务?
定制开发 / 二次开发

基于 stefangabos/zebra_cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2022-08-15