PHPackages                             rodrigovr/php-aop-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. rodrigovr/php-aop-cache

ActiveLibrary[Caching](/categories/caching)

rodrigovr/php-aop-cache
=======================

Cache method calls using Aspect-Oriented Programming techniques.

00PHP

Since Sep 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/rodrigovr/php-aop-cache)[ Packagist](https://packagist.org/packages/rodrigovr/php-aop-cache)[ RSS](/packages/rodrigovr-php-aop-cache/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

php-aop-cache
=============

[](#php-aop-cache)

Aspect-Oriented Caching of Method Calls Using Runkit7

Goals
-----

[](#goals)

This project allows you to decorate method calls with a caching behavior. In other words, this means that, without modifing the source code of a foreign class, you can "plug" a cache mechanism to a choosen public method.

When is it useful?
------------------

[](#when-is-it-useful)

1. Before refactoring large code bases.
2. When dealing with third-party code.
3. To avoid licensing issues.
4. To avoid repeated code.
5. To easily test caching backends.

This is not a complete list, just some insights!

Dependencies
------------

[](#dependencies)

- install and enable runkit7
- php 7.2+

What can be cached?
-------------------

[](#what-can-be-cached)

You must decorate only user defined methods. Native classes are not supported.

Ex: You cannot attach directly to PDO::query.

How to use?
-----------

[](#how-to-use)

1. install with composer: `composer require rodrigovr/php-aop-cache`
2. as soon as possible, instantiate the Decorator with a given cache implementation:

```
use rodrigovr\Aop;

...

$decorator = Cache\Decorator::create(new Cache\MemoryCache);
```

3. attach the decorator to any methods you want to cache results:

```
$decorator->attachTo('SomeClass', 'methodName')
          ->attachTo('SomeClass', 'anotherMethodName')
          ->attachTo('AnotherClass', 'oneMoreMethod');
```

4. if needed, set how long (in seconds), results will be cached

```
// cache results up to 5 minutes
$decorator->expires(300);
```

5. you can also limit cache entries by size (in bytes)

```
// results over 10MB will not be saved
$decorator->limit(10000000);
```

6. multiple decorators are supported

```
$applyMemoryCache = Cache\Decorator::create(new Cache\MemoryCache);
$applySessionCache = Cache\Decorator::create(new Cache\SessionCache);
$applyApcuCache = Cache\Decorator::create(new Cache\SessionCache);
```

7. you can create custom caching backends

```
use rodrigovr\Aop;

class MyCache implements Cache\Storage {
    public function save($key, $value, $ttl) {
        // your custom save implementation
    }
    public function load($key) {
        // custom load implementation
    }
}

$decorator = Cache\Decorator::create(new MyCache)->expires(120);
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4616411?v=4)[rodrigovr](/maintainers/rodrigovr)[@rodrigovr](https://github.com/rodrigovr)

---

Top Contributors

[![rodrigovr](https://avatars.githubusercontent.com/u/4616411?v=4)](https://github.com/rodrigovr "rodrigovr (5 commits)")

### Embed Badge

![Health badge](/badges/rodrigovr-php-aop-cache/health.svg)

```
[![Health](https://phpackages.com/badges/rodrigovr-php-aop-cache/health.svg)](https://phpackages.com/packages/rodrigovr-php-aop-cache)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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