PHPackages                             andydune/retain-cache-on-data-absent - 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. andydune/retain-cache-on-data-absent

ActiveLibrary[Caching](/categories/caching)

andydune/retain-cache-on-data-absent
====================================

Code allow restore data in cache if new data can not be retrieved.

v1.1.1(7y ago)015MITPHPPHP &gt;=5.6CI failing

Since Jun 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/AndyDune/RetainCacheOnDataAbsent)[ Packagist](https://packagist.org/packages/andydune/retain-cache-on-data-absent)[ Docs](https://github.com/AndyDune/RetainCacheOnDataAbsent)[ RSS](/packages/andydune-retain-cache-on-data-absent/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

RetainCacheOnDataAbsent
=======================

[](#retaincacheondataabsent)

[![Build Status](https://camo.githubusercontent.com/27595a494df9d53cf2cea1ad77bf8b329638f904ffc110052d72622eac757e87/68747470733a2f2f7472617669732d63692e6f72672f416e647944756e652f52657461696e43616368654f6e44617461416273656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AndyDune/RetainCacheOnDataAbsent)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/21bec099e09499cb01fd2ca13967d42e5441d7d9981697560623ace539553c5a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e647964756e652f72657461696e2d63616368652d6f6e2d646174612d616273656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andydune/retain-cache-on-data-absent)[![Total Downloads](https://camo.githubusercontent.com/68a0613358c4f0cc8e0ffe511f8cfeafe74fdf71c13b360ded27cad301bf2a87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647964756e652f72657461696e2d63616368652d6f6e2d646174612d616273656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andydune/retain-cache-on-data-absent)

It allows to restore data in cache if new data can not be retrieved.

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

[](#installation)

Installation using composer:

```
composer require andydune/retain-cache-on-data-absent

```

Or if composer was not installed globally:

```
php composer.phar require andydune/retain-cache-on-data-absent

```

Or edit your `composer.json`:

```
"require" : {
     "andydune/retain-cache-on-data-absent": "^1"
}

```

And execute command:

```
php composer.phar update

```

Problem
-------

[](#problem)

Yor script gets data from external API. For example currency rate from [crr](https://github.com/AndyDune/CurrencyRateCbr).

There is no need to extract data every time it is needed. So we are using cache. But what will be if cache get old, but no data appears from api? There is network error or bank site breakage.

This little library helps to avoid data absent from retriever. Cached data do not expires and if no new data appears it uses old data from cache.

Using
-----

[](#using)

```
use Symfony\Component\Cache\Simple\FilesystemCache;
use AndyDune\RetainCacheOnDataAbsent\Cache;

$cacheAdapter = new FilesystemCache('test', 3600, '');
$cache = new Cache($cacheAdapter, function () {
    /*
        $data = false; // no data - return data from old cache
        $data = 'very useful data to cache and use'; // update cache and return this data
    */
    return $data;
});
$result = $cache->get('data'); // use any key - it is used only for cache key
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

2884d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79da3b2173a2cefb36abc9b4707cf2c633df8f2c748633ccf64186f5c0e7be6c?d=identicon)[AndyDune](/maintainers/AndyDune)

---

Top Contributors

[![AndyDune](https://avatars.githubusercontent.com/u/3772910?v=4)](https://github.com/AndyDune "AndyDune (13 commits)")

---

Tags

phpcache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andydune-retain-cache-on-data-absent/health.svg)

```
[![Health](https://phpackages.com/badges/andydune-retain-cache-on-data-absent/health.svg)](https://phpackages.com/packages/andydune-retain-cache-on-data-absent)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

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

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[eftec/cacheone

A Cache library with minimum dependency

103.5k4](/packages/eftec-cacheone)

PHPackages © 2026

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