PHPackages                             genesis/method-persister - 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. genesis/method-persister

ActiveLibrary[Caching](/categories/caching)

genesis/method-persister
========================

Allows caching of any method in code.

1.0.3(6y ago)1315[1 PRs](https://github.com/forceedge01/method-cacher/pulls)1MITPHP ~7.1

Since Apr 24Compare

[ Source](https://github.com/forceedge01/method-cacher)[ Packagist](https://packagist.org/packages/genesis/method-persister)[ RSS](/packages/genesis-method-persister/feed)WikiDiscussions Synced 2mo ago

READMEChangelogDependencies (1)Versions (7)Used By (1)

Method Persister/Cacher [ ![Codeship Status for forceedge01/method-cacher](https://camo.githubusercontent.com/128267f4cbf1461a5fe7607e2e718882b04f26b1abde837a6a64eddc9f43504b/68747470733a2f2f6170702e636f6465736869702e636f6d2f70726f6a656374732f64616465326566302d616434382d303133352d633262382d3065373435626131333332322f7374617475733f6272616e63683d6d6173746572)](https://app.codeship.com/projects/257185)
=================================================================================================================================================================================================================================================================================================================================================================================================================

[](#method-persistercacher--)

What is this?
=============

[](#what-is-this)

This library allows caching the result of methods for a specified amount of time. This can be on a global level or per user session.

Installation
============

[](#installation)

Using composer:

```
composer require "genesis/method-persister"
```

Instantiation
=============

[](#instantiation)

```
namespace ABC\Example;

use Genesis\MethodPersister;

// Ideally done using a DI library.
$centralStoragePath = '/tmp/cache/';
$persistenceRepository = new MethodPersister\PersistenceRepository($centralStoragePath);
$persister = new MethodPersister\Persister($persistenceRepository);
```

Usage
=====

[](#usage)

Consider your code like this:

```
$result = $myObject->myMethod($arg1, $arg2);

return $result;
```

The above can be rewritten with the cacher as follows yielding the same but faster results.

```
$result = $persister->persist($myObject, 'myMethod')
	->withParameters($arg1, $arg2)
	->overAPeriodOf('+10 seconds')
	->execute();

// Use result as normal
return $result;
```

This will persist the cache for 10 seconds from the first call, after that the cache will be refreshed. The default storage method is centralised but can be changed to distributed i.e session caching using the `->in()` method.

```
$result = $persister->persist($myObject, 'userSpecificData')
    ->withParameters($arg1, $arg2)
    ->overAPeriodOf('+10 seconds')
    ->in(PersisterInterface::STATE_DISTRIBUTE)
    ->execute();
```

Contributions
=============

[](#contributions)

This project is in its early stages, forks are welcome :)

Tests
=====

[](#tests)

Library is tested using phpunit. To run tests first install dependencies using composer then run command:

```
make
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

2191d ago

Major Versions

0.1.0 → 1.0.02020-05-15

PHP version history (2 changes)1.0.0PHP 7.1

1.0.1PHP ~7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4529502cab11a6993a59a1d1a2818f438d073636e3f59dd617a259be74e3feae?d=identicon)[forceedge](/maintainers/forceedge)

---

Top Contributors

[![forceedge01](https://avatars.githubusercontent.com/u/1619816?v=4)](https://github.com/forceedge01 "forceedge01 (12 commits)")

---

Tags

persistencecachingmethod-cachehtml cachemethod cachingmethod persistcontroller cache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/genesis-method-persister/health.svg)

```
[![Health](https://phpackages.com/badges/genesis-method-persister/health.svg)](https://phpackages.com/packages/genesis-method-persister)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[overblog/dataloader-php

DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

2124.2M6](/packages/overblog-dataloader-php)[spatie/blink

Cache that expires in the blink of an eye

1685.0M8](/packages/spatie-blink)

PHPackages © 2026

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