PHPackages                             gwa/gw-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. gwa/gw-cache

ActiveLibrary[Caching](/categories/caching)

gwa/gw-cache
============

PHP simple cache classes

v2.0(11y ago)17051MITPHP

Since Sep 3Pushed 11y ago4 watchersCompare

[ Source](https://github.com/gwa/gwCache)[ Packagist](https://packagist.org/packages/gwa/gw-cache)[ Docs](https://github.com/gwa/gwCache)[ RSS](/packages/gwa-gw-cache/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (3)Versions (10)Used By (1)

gwCache
=======

[](#gwcache)

A simple but flexible PHP cache

[![Quality Score](https://camo.githubusercontent.com/179e26ed2027204b56a0d97b22f5b3c0c36500eb9f53df1812d30ff939e0b570/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6777612f677743616368652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gwa/gwCache/code-structure/master) [![Build Status](https://camo.githubusercontent.com/a53601a4cba46392d5df88c5bbee576790d0b9a2dcb3f764856e3a1f384b7c41/68747470733a2f2f6170692e7472617669732d63692e6f72672f6777612f677743616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gwa/gwCache)

Usage
-----

[](#usage)

### Installation

[](#installation)

Install [package](https://packagist.org/packages/gwa/gw-cache) via composer.

```
composer require gwa/gw-cache
```

### Using the cache

[](#using-the-cache)

```
use Gwa\Cache\Cache;

// Create a persistence layer for the cache
// Cache directory should be writable.
// (Cache will try to create it if it does not exist.)
$cachedir = __DIR__ . '/cachestore';
$persistence = new CacheDirectoryPersistence($cachedir);

// Set an optional group for the cache
$group = '';

// Set cache validity in minutes
$cacheminutes = 60 * 12;

// create a cache instance using an identifier unique to the group
$cache = new Cache('myidentifier', $group, $cacheminutes);
$cache->setPersistence($persistence);

$iscached = $cache->isCached(); // false

// write a value to the cache
$cache->set('foo');

// new object, same group and identifier
$cache2 = new Cache('myidentifier', $group, $cacheminutes);
$cache2->setPersistence($persistence);
$iscached = $cache2->isCached(); // true
$value = $cache2->get(); // 'foo'

// clear the cache
$cache2->clear();
$iscached = $cache2->isCached(); // false
```

### Using a factory

[](#using-a-factory)

Instead of always passing in the persistence layer, a factory can be used.

The factory could be set up as a service in your app (using, for example, [Pimple](http://pimple.sensiolabs.org/)). Creating a cache instance is then not dependent on the persistence layer.

```
$factory = new CacheFactory(new CacheDirectoryPersistence($cachedir));

$cache = $factory->create('myidentifier', $group, $cacheminutes);
```

### Caching serialized data

[](#caching-serialized-data)

To cache complex PHP types (ie. objects), set the cache type argument when creating the cache instance.

```
$cache = new Cache('myidentifier', $group, $cacheminutes, Cache::TYPE_OBJECT);

// with a factory
$cache = $factory->create('myidentifier', $group, $cacheminutes, Cache::TYPE_OBJECT);
```

### Custom persistence layers

[](#custom-persistence-layers)

You can roll your own persistence layer (MySQL, memcache, redis) by creating a class that implements the `CachePersistenceInterface` interface.

If you are using a factory-as-a-service architecture, you can use different persistence layers in different environments without changing the code that uses the service.

Contributing
------------

[](#contributing)

All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.

Fork the project, create a feature branch, and send us a pull request.

To ensure a consistent code base, you should make sure the code follows the [Coding Standards](http://www.php-fig.org/psr/psr-2/)which we borrowed from PSR-2.

The easiest way to do make sure you're following the coding standard is to run `vendor/bin/php-cs-fixer fix` before committing.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 65.4% 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 ~36 days

Recently: every ~23 days

Total

8

Last Release

4113d ago

Major Versions

v1.5 → v2.02015-05-14

### Community

Maintainers

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

---

Top Contributors

[![gwagroves](https://avatars.githubusercontent.com/u/8222012?v=4)](https://github.com/gwagroves "gwagroves (17 commits)")[![prisis](https://avatars.githubusercontent.com/u/2716058?v=4)](https://github.com/prisis "prisis (8 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gwa-gw-cache/health.svg)

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

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)

PHPackages © 2026

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