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

ActiveLibrary[Caching](/categories/caching)

leafs/cache
===========

Leaf PHP cache module

v0.1.0(8mo ago)1148MITPHP

Since Sep 6Pushed 8mo agoCompare

[ Source](https://github.com/leafsphp/cache)[ Packagist](https://packagist.org/packages/leafs/cache)[ Docs](https://leafphp.dev/docs/utils/cache)[ GitHub Sponsors](https://github.com/leafsphp)[ Fund](https://opencollective.com/leaf)[ RSS](/packages/leafs-cache/feed)WikiDiscussions main Synced 1mo ago

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

 [![](https://camo.githubusercontent.com/d98ee5e32c2ff016fdfdac6c42654a908f4cc34b229c7b00caacc5a717455ae8/68747470733a2f2f6c6561667068702e6465762f6c6f676f2d636972636c652e706e67)](https://camo.githubusercontent.com/d98ee5e32c2ff016fdfdac6c42654a908f4cc34b229c7b00caacc5a717455ae8/68747470733a2f2f6c6561667068702e6465762f6c6f676f2d636972636c652e706e67)

Leaf Cache
==========

[](#leaf-cache)

Cache module for Leaf.

```
leaf install cache
```

Or with composer:

```
composer require leafs/cache
```

Usage
-----

[](#usage)

You can use the cache module to store data, usually to avoid repeated expensive operations.

Cache data forever:

```
$value = cache(
    'key',
    function() {
        // expensive operation
        return 'value';
    },
);
```

Cache data for a specific time (in seconds):

```
$value = cache(
    'key',
    600, // 10 minutes
    function() {
        // expensive operation
        return 'value';
    },
);
```

Unlike other frameworks, the cache function will always return the cached value if it exists, meaning that the closure will only be executed if the cache key does not exist. So you don't need to check if the value exists before calling the cache function.

Extended Usage
--------------

[](#extended-usage)

The cache module is built on top of the Illuminate Cache component, so you can use all the features of that component. To do that, you can call the `cache()` function without any parameters to get the cache repository instance:

```
cache()->put('key', 'value', 600); // cache for 10 minutes
$value = cache()->get('key');
```

For most use cases, the `cache()` function is sufficient, but if you need more control, you can use the cache repository instance directly.

You can use this to manually overwrite a cache key:

```
// will not set the cache if it already exists
cache('key', 600, 'new value'); // cache for 10 minutes

// will always set the cache, even if it already exists
cache()->put('key', 'new value', 600); // cache for 10 minutes
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance65

Regular maintenance activity

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity25

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

245d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

cacheleafPHP

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[anahkiasen/flatten

A package for the Illuminate framework that flattens pages to plain HTML

33313.0k](/packages/anahkiasen-flatten)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k9](/packages/dragon-code-laravel-cache)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

1317.7k](/packages/nexxai-laravel-cfcache)[omaralalwi/lexi-translate

Laravel translation package with morph relationships and caching.

754.3k2](/packages/omaralalwi-lexi-translate)[suitmedia/laravel-cacheable

Decorate your repositories and make them cacheable

1237.7k](/packages/suitmedia-laravel-cacheable)

PHPackages © 2026

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