PHPackages                             popphp/pop-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. popphp/pop-cache

ActiveLibrary[Caching](/categories/caching)

popphp/pop-cache
================

Pop Cache Component for Pop PHP Framework

4.0.3(6mo ago)66.4k↓50%1BSD-3-ClausePHPPHP &gt;=8.3.0CI passing

Since Jul 16Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/popphp/pop-cache)[ Packagist](https://packagist.org/packages/popphp/pop-cache)[ Docs](https://github.com/popphp/pop-cache)[ RSS](/packages/popphp-pop-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (26)Used By (1)

pop-cache
=========

[](#pop-cache)

[![Build Status](https://github.com/popphp/pop-cache/workflows/phpunit/badge.svg)](https://github.com/popphp/pop-cache/actions)[![Coverage Status](https://camo.githubusercontent.com/784a97783ef5f523e37aa0088573a96526d742da89aadd7ff9363f94ea5d6625/687474703a2f2f63632e706f707068702e6f72672f636f7665726167652e7068703f636f6d703d706f702d6361636865)](http://cc.popphp.org/pop-cache/)

[![Join the chat at https://discord.gg/TZjgT74U7E](https://camo.githubusercontent.com/acad7b0eeb78b78d08ffd2b85681ab243436388b5f86f8bcb956a69246e53739/68747470733a2f2f6d656469612e706f707068702e6f72672f696d672f646973636f72642e737667)](https://discord.gg/TZjgT74U7E)

- [Overview](#overview)
- [Install](#install)
- [Quickstart](#quickstart)
- [APC](#apc)
- [Memcached](#memcached)
- [Redis](#redis)
- [File](#file)
- [Database](#database)
- [Session](#session)

Overview
--------

[](#overview)

`pop-cache` provides the ability to cache frequently accessed content via several different adapters. The adapters all share the same interface and are interchangeable. Depending on the server environment and what's available, an application can use one of the following cache adapters:

- Apc (caching service)
- Memcached (caching service)
- Redis (caching service)
- File (directory on disk)
- Database (database caching)
- Session (short-term caching in session)

`pop-cache` is a component of the [Pop PHP Framework](https://www.popphp.org/).

[Top](#pop-cache)

Install
-------

[](#install)

Install `pop-cache` using Composer.

```
composer require popphp/pop-cache

```

Or, require it in your composer.json file

```
"require": {
    "popphp/pop-cache" : "^4.0.3"
}

```

[Top](#pop-cache)

Quickstart
----------

[](#quickstart)

Here is a basic example to create a cache object and then save and retrieve some data from it. The adapter can be passed a "time-to-live" value in seconds (TTL). If set to `0`, then the cached items will never expire:

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\File;

// Passing the file adapter the location on disk and the TTL
$cache = new Cache(new Adapter\File('/path/to/my/cache/dir', 300));

$cache->saveItem('foo', $data);

$data = $cache->getItem('foo');
```

### Check if the cache has an item

[](#check-if-the-cache-has-an-item)

```
if $cache->hasItem('foo') { } // Return bool
```

### Delete item

[](#delete-item)

```
$cache->deleteItem('foo');
```

### Delete items

[](#delete-items)

```
$cache->deleteItems(['foo', 'bar']);
```

### Clear all items out of the cache

[](#clear-all-items-out-of-the-cache)

```
$cache->clear();
```

[Top](#pop-cache)

APC
---

[](#apc)

Using the APC adapter requires APC to be correctly set up in the environment.

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\Apc;

$cache = new Cache(new Apc(300));
```

[Top](#pop-cache)

Memcached
---------

[](#memcached)

Using the Memcached adapter requires Memcached to be correctly set up in the environment.

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\Memcached;

$cache = new Cache(new Memcached(300, 'localhost', 11211));
```

[Top](#pop-cache)

Redis
-----

[](#redis)

Using the Redis adapter requires Redis to be correctly set up in the environment.

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\Redis;

$cache = new Cache(new Redis(300, 'localhost', 6379));
```

[Top](#pop-cache)

File
----

[](#file)

Using the file adapter will simply store the cache data on the local disk.

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\File;

$cache = new Cache(new Adapter\File('/path/to/my/cache/dir', 300));
```

[Top](#pop-cache)

Database
--------

[](#database)

Using the database adapter will require the database to be set up correctly and the use of the `pop-db` component.

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\Database;
use Pop\Db\Db;

$cache = new Cache(
    new Database(Db::sqliteConnect(['database' => __DIR__ . '/tmp/cache.sqlite']), 300)
);
```

[Top](#pop-cache)

Session
-------

[](#session)

Using the session adapter will store the cached data in session

```
use Pop\Cache\Cache;
use Pop\Cache\Adapter\Session;

$cache = new Cache(new Session(300));
```

[Top](#pop-cache)

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance67

Regular maintenance activity

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 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 ~188 days

Recently: every ~271 days

Total

21

Last Release

196d ago

Major Versions

2.1.0 → 3.0.02016-07-10

3.4.1 → 4.0.02023-12-18

PHP version history (8 changes)2.0.0PHP &gt;=5.4.0

3.1.0PHP &gt;=5.6.0

3.2.3PHP &gt;=7.1.0

3.4.0PHP &gt;=7.3.0

3.4.1PHP &gt;=7.4.0

4.0.0PHP &gt;=8.1.0

4.0.1PHP &gt;=8.2.0

4.0.3PHP &gt;=8.3.0

### Community

Maintainers

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

---

Top Contributors

[![nicksagona](https://avatars.githubusercontent.com/u/898670?v=4)](https://github.com/nicksagona "nicksagona (83 commits)")

---

Tags

phprediscachecachingapcmemcachepoppop php

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/popphp-pop-cache/health.svg)

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

###  Alternatives

[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[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)[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)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)

PHPackages © 2026

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