PHPackages                             stefangabos/zebra\_cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. stefangabos/zebra\_cache

ActiveLibrary[Caching](/categories/caching)

stefangabos/zebra\_cache
========================

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

2.0.0(1y ago)235LGPL-3.0-onlyPHPPHP &gt;=7CI passing

Since Aug 15Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/stefangabos/Zebra_Cache)[ Packagist](https://packagist.org/packages/stefangabos/zebra_cache)[ Docs](https://github.com/stefangabos/Zebra_Cache)[ RSS](/packages/stefangabos-zebra-cache/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (9)Dependencies (3)Versions (10)Used By (0)

[![Zebra Cache Logo](https://github.com/stefangabos/zebrajs/raw/master/docs/images/logo.png)](https://github.com/stefangabos/zebrajs/blob/master/docs/images/logo.png)

Zebra Cache [![Tweet](https://camo.githubusercontent.com/cb820a0ecc9645168e33b03925d7f14691262ddbaeaf66a0a91697803d0cba2d/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=A+file-based+lightweight+PHP+caching+library+that+uses+file+locking+to+ensure+proper+functionality+under+heavy+load&url=https://github.com/stefangabos/Zebra_Cache&via=stefangabos&hashtags=php,cache)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#zebra-cache-)

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

[![Latest Stable Version](https://camo.githubusercontent.com/61cdd4b9a4bd71fbec740e605928d4a72df55fec45fb8da191c83d1ad767f7a8/68747470733a2f2f706f7365722e707567782e6f72672f73746566616e6761626f732f7a656272615f63616368652f762f737461626c65)](https://packagist.org/packages/stefangabos/zebra_cache) [![Total Downloads](https://camo.githubusercontent.com/75046a1778113d9dbb79cae790e5a8296609c10df6ecb248f9b75ecbe7f9dbd1/68747470733a2f2f706f7365722e707567782e6f72672f73746566616e6761626f732f7a656272615f63616368652f646f776e6c6f616473)](https://packagist.org/packages/stefangabos/zebra_cache) [![Monthly Downloads](https://camo.githubusercontent.com/1fdd54f75ee1205deb8bad63797704287b5b5f6b9bbd41640f69be14cbb93601/68747470733a2f2f706f7365722e707567782e6f72672f73746566616e6761626f732f7a656272615f63616368652f642f6d6f6e74686c79)](https://packagist.org/packages/stefangabos/zebra_cache) [![Daily Downloads](https://camo.githubusercontent.com/d09b43697f41cb28bbdb90d5784cbd60cd0a16041f4e2aa37b63eb3f4a1e88ea/68747470733a2f2f706f7365722e707567782e6f72672f73746566616e6761626f732f7a656272615f63616368652f642f6461696c79)](https://packagist.org/packages/stefangabos/zebra_cache) [![License](https://camo.githubusercontent.com/5782e265bc88d78f0325b8e8fec23beb2f193b4f45acc15a036b8d0e42bfb8a3/68747470733a2f2f706f7365722e707567782e6f72672f73746566616e6761626f732f7a656272615f63616368652f6c6963656e7365)](https://packagist.org/packages/stefangabos/zebra_cache)

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
--------

[](#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
---------------

[](#notebook_with_decorative_cover-documentation)

Check out the [awesome documentation](https://stefangabos.github.io/Zebra_Cache/Zebra_Cache/Zebra_Cache.html)!

🎂 Support the development of this project
-----------------------------------------

[](#-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](https://camo.githubusercontent.com/091b8b9b8df46ebb5ab9e03c7d809984b7c01bcf13cdda939843c073624907be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f73746566616e6761626f732f7a656272615f63616368653f636f6c6f723d677265656e266c6162656c3d7374617225323069742532306f6e253230476974487562)](https://github.com/stefangabos/Zebra_Cache) [![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W6MCFT65DRN64) [![](https://camo.githubusercontent.com/7a6725dd6857bfabaca4b6783ac9ff3c2e882456681b5fdfb1fae916c0461c73/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d53706f6e736f722d6661666266633f6c6f676f3d47697448756225323053706f6e736f7273)](https://github.com/sponsors/stefangabos)

Requirements
------------

[](#requirements)

PHP 7.0.0+

Use version [1.3.2](https://github.com/stefangabos/Zebra_Cache/releases/tag/1.3.2) if you need support for PHP 5.3.0+

Installation
------------

[](#installation)

Install via [Composer](https://packagist.org/packages/stefangabos/zebra_cache)

```
# 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-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](https://memcached.org/): the [memcache](https://www.php.net/manual/en/book.memcache.php) extension, which is older and less commonly used, and [memcached](https://www.php.net/manual/en/book.memcached.php) 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
--------------------------------------------------------

[](#initializing-the-main-library-and-settinggetting-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

[](#getting-information-about-cached-data)

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

    print_r('');
    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

[](#deleting-cached-data)

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

###  Health Score

38

↑

LowBetter than 84% of packages

Maintenance71

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~110 days

Recently: every ~186 days

Total

9

Last Release

481d ago

Major Versions

1.4.1 → 2.0.02025-01-12

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1089e48cafe9a5737b8512d9fddff8596b9ef102276f25b6361bc6781d108aa?d=identicon)[stefangabos](/maintainers/stefangabos)

---

Top Contributors

[![stefangabos](https://avatars.githubusercontent.com/u/741165?v=4)](https://github.com/stefangabos "stefangabos (95 commits)")

---

Tags

cachecomposer-packagefile-cachekey-value-storelightweightmemcachedphpphp-cachephp-librarypsr-16redisttlphpfilesystemperformancerediscachecachingmemcachecache library

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stefangabos-zebra-cache/health.svg)

```
[![Health](https://phpackages.com/badges/stefangabos-zebra-cache/health.svg)](https://phpackages.com/packages/stefangabos-zebra-cache)
```

###  Alternatives

[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[ymigval/laravel-model-cache

Laravel package for caching Eloquent model queries

7642.2k3](/packages/ymigval-laravel-model-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
