PHPackages                             mattmezza/cacheasy - 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. mattmezza/cacheasy

ActiveLibrary[Caching](/categories/caching)

mattmezza/cacheasy
==================

I hate slow APIs, I cache things on disk.

1.1(8y ago)218MITPHPPHP ^7.1

Since Mar 30Pushed 8y ago2 watchersCompare

[ Source](https://github.com/mattmezza/cacheasy)[ Packagist](https://packagist.org/packages/mattmezza/cacheasy)[ RSS](/packages/mattmezza-cacheasy/feed)WikiDiscussions master Synced 4w ago

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

cacheasy
========

[](#cacheasy)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cf05655e7c80348749f19b4fb92df54e1295f66e7917d4560db1ae918ec34505/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6174746d657a7a612f63616368656173792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mattmezza/cacheasy/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/114d98c57af21eab122d1d8eb972dde075fb24d679b9b93def38aa2354e095ed/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6174746d657a7a612f63616368656173792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mattmezza/cacheasy/?branch=master) [![Build Status](https://camo.githubusercontent.com/17239c3aaafc3d43d05d540d3f16e3a06120cbeb18264cb09017f1fd76c45656/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6174746d657a7a612f63616368656173792f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mattmezza/cacheasy/build-status/master)

> I hate slow APIs, I cache things on disk.

Install
=======

[](#install)

`composer require mattmezza/cacheasy`

Usage
=====

[](#usage)

With string responses:

```
$providerStrAPI = new class implements Cacheasy\StringProvider {
    public function get() : string
    {
        return (new SlowAPIsClient())->slowAPI();
    }
};
// ./cache is the cache path, 86400 is the time to live
$cache = new Cache("./cache", 86400);
// if slowAPI is not cached let's get the data and cache them
$result = $cache->getString("slowAPI", $providerStrAPI); # this is slow :(
$result2 = $cache->getString("slowAPI", $providerStrAPI); # this is blazing fast :)
echo $result2;
```

With JSON responses:

```
$providerJsonAPI = new class implements Cacheasy\JsonProvider {
    public function get() : array
    {
        return (new SlowAPIsClient())->slowAPI();
    }
};
// ./cache is the cache path, 86400 is the time to live
$cache = new Cache("./cache", 86400);
// if slowAPI is not cached let's get the data and cache them
$result = $cache->getJson("slowjsonAPI", $providerJsonAPI); # this is slow :(
$result2 = $cache->getJson("slowjsonAPI", $providerJsonAPI); # this is blazing fast :)
echo $result2["property"];
```

API
===

[](#api)

- `cacheString($key, $string) : string`: caches a string with key
- `cacheJson($key, $array) : array`: caches an array to json with key
- `hitString($key) : string`: tries to resume from cache a string with key
- `hitJson($key) : array`: tries to resume from cache a json with key
- `isCached($key) : bool`: checks if key is cached on disk and if it is not expired
- `getJson($key, $provider = null, bool $forceFresh = false) : array`: returns `hitJson(...)` if key is cached, calls provider otherwise. Throws exception if $provider is null and $key is not cached. If $forceFresh is set to `true` skips isCached check and calls the provider (ultimately caching the data).
- `getString($key, $provider = null, bool $forceFresh = false) : string`: returns `hitString(...)` if key is cached, calls provider otherwise. Throws exception if $provider is null and $key is not cached. If $forceFresh is set to `true` skips isCached check and calls the provider (ultimately caching the data).
- `invalidate($key) : void`: deletes the cached resource
- `invalidateAll() : void`: deletes all the cached resources

Exceptions
----------

[](#exceptions)

`MissingProviderException`: when `get..(...)` is called for a non cached resource and no provider is passed, or when, even if the resource is cached, the method is invoked with null provider and with `true` force fresh values. `NotCachedException`: when you wanna hit the cache but the resource is not cached yet.

Development
===========

[](#development)

- `git clone https://github.com/mattmezza/cacheasy.git`
- `cd cacheasy`
- `composer test`

##### Matteo Merola

[](#matteo-merola-mattmezzagmailcom)

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Total

2

Last Release

3055d ago

PHP version history (2 changes)1.0.0PHP ^7.0

1.1PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1915989?v=4)[Matteo Merola](/maintainers/mattmezza)[@mattmezza](https://github.com/mattmezza)

---

Tags

apicachecachingcaching-librarydiskslow

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mattmezza-cacheasy/health.svg)

```
[![Health](https://phpackages.com/badges/mattmezza-cacheasy/health.svg)](https://phpackages.com/packages/mattmezza-cacheasy)
```

###  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)

PHPackages © 2026

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