PHPackages                             xinningsu/laravel-easy-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. xinningsu/laravel-easy-cache

ActiveLibrary[Caching](/categories/caching)

xinningsu/laravel-easy-cache
============================

Easy way to cache the result of service method as demand.

v1.0.0(5y ago)011MITPHPPHP &gt;=5.6

Since Jan 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/xinningsu/laravel-easy-cache)[ Packagist](https://packagist.org/packages/xinningsu/laravel-easy-cache)[ RSS](/packages/xinningsu-laravel-easy-cache/feed)WikiDiscussions master Synced 2d ago

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

Laravel Easy Cache
==================

[](#laravel-easy-cache)

Easy way to cache the result of a service method on demand.

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE)[![Build Status](https://camo.githubusercontent.com/cf38ba2ad3baeb98d148b81b4bb0e899df65cfededf007114114436cf31fda44/68747470733a2f2f6170692e7472617669732d63692e6f72672f78696e6e696e6773752f6c61726176656c2d656173792d63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/xinningsu/laravel-easy-cache)[![Coverage Status](https://camo.githubusercontent.com/3d1d97a7f8a6a4147a0ad0907e0ca61ad72e93b8f250b87d7012e87b414eda21/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f78696e6e696e6773752f6c61726176656c2d656173792d63616368652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/xinningsu/laravel-easy-cache)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ee8ac6f9891d3c1bb46aff8ebdbc608567ba1b169ef8f0d2ffdb922ee3b2946f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f78696e6e696e6773752f6c61726176656c2d656173792d63616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/xinningsu/laravel-easy-cache)[![Code Intelligence Status](https://camo.githubusercontent.com/5c08a9e22b4ac19564f7f60fa03c8539c5d9588b845ad1b7ad7ec7338fc680e6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f78696e6e696e6773752f6c61726176656c2d656173792d63616368652f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/g/xinningsu/laravel-easy-cache)[![Quality Gate Status](https://camo.githubusercontent.com/ef1d7d25067131e5f43e837b194a034b6b51ab96e40f9f270df501f1642388b6/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d78696e6e696e6773755f6c61726176656c2d656173792d6361636865266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-easy-cache)[![Reliability Rating](https://camo.githubusercontent.com/2c8d2bf19a6c5804a9016756d082eda07d638dbb30b6a80da951c203a45ddc8b/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d78696e6e696e6773755f6c61726176656c2d656173792d6361636865266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-easy-cache)[![Security Rating](https://camo.githubusercontent.com/d0eb863b81c70dc6554ba5060e9f3165df1fb49859c15d4adde6e52fb55deb1c/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d78696e6e696e6773755f6c61726176656c2d656173792d6361636865266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-easy-cache)[![Maintainability](https://camo.githubusercontent.com/361ad96283dd333822e3e84e5bb44ae5a64eca405f859419aca2d699448fd88e/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31383636393338366365363535333262323238662f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/xinningsu/laravel-easy-cache/maintainability)

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

[](#installation)

Require this package with composer.

```
composer require xinningsu/laravel-easy-cache

```

\[Optional\] Copy `config/easy-cache.php` of this package to `config/easy-cache.php` under laravel project and custom it. see [Global Configuration](#global-configuration) for more detail.

Usage
=====

[](#usage)

Use EasyCache trait in a service class

```
class News
{
    use \Sulao\EasyCache\EasyCache;

    public function getTopNews($limit = 5)
    {
        $news = [
            ['id' => 1, 'title' => 'news 1'],
            ['id' => 2, 'title' => 'news 2'],
            ['id' => 3, 'title' => 'news 3'],
            ['id' => 4, 'title' => 'news 4'],
            ['id' => 5, 'title' => 'news 5'],
        ];

        return array_slice($news, 0, $limit);
    }
}
```

Now the result of the service method can be cached on demand.

```
$news = new News();

// without caching
$topNews = $news->getTopNews(2);

// cache it with default configuration, ttl: 3600,
// key: serialize class name, method name and parameters as cache key,
// store: laravel default cache store
// see Global Configuration below to custom default configuration.
$topNews = $news->cache()->getTopNews(2);

// or specify the ttl
$topNews = $news->cache(300)->getTopNews(2);

// specify the ttl and cache key,
// please notice that the cache key has to be specified if there is
// a closure in parameters, because closure can not be serialized.
$topNews = $news->cache(300, 'cache-key')->getTopNews(2);

// specify ttl, cache key and store,
// store is the store defined in laravel config/cache.php
$topNews = $news->cache(300, 'cache-key', 'array')->getTopNews(2);
```

Global Configuration
====================

[](#global-configuration)

If you want custom global config, copy config/easy-cache.php of this package to config/easy-cache.php under your laravel project.

```
return [
    // If the ttl parameter is not specified when calling cache method,
    // then use this one, default value is 3600.
    'ttl' => 3600,

    // Value can be the store defined in config/cache.php of laravel project,
    // such as memcached, redis ... If null, using laravel default cache store.
    'store' => null,

    // This prefix will be added to the front of each cache key, so it can
    // easily refresh the whole cache by changing this. default value is null.
    'prefix' => null,

    // If this specified, the caches in the page can be refreshed via query string,
    // see Refresh Page Cache below.
    'refresh_key' => null,
];
```

Refresh Page Cache
==================

[](#refresh-page-cache)

Firstly have to defined `refresh_key` in [config/easy-cache.php](#global-configuration), such as

```
    'refresh_key' => 'clear_cache',

```

Then open the page and add the query string like this

```
http://localhots/?clear_cache=1

```

Will refresh all the caches of that page, notice that just the caches of the page, not all the caches in the store.

License
=======

[](#license)

[MIT](./LICENSE)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

1950d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7513c529acb322b54c46bef8011275fe734f9d00944c3f3921cebc21c0cd2ed0?d=identicon)[xinningsu](/maintainers/xinningsu)

---

Tags

cacheeasy-cachelaravel

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/xinningsu-laravel-easy-cache/health.svg)

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

###  Alternatives

[imanghafoori/laravel-widgetize

A minimal yet powerful package to give a better structure and caching opportunity for your Laravel apps.

909137.9k12](/packages/imanghafoori-laravel-widgetize)[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)[alexmg86/laravel-sub-query

Laravel subquery

7538.4k](/packages/alexmg86-laravel-sub-query)[laravel-enso/rememberable

Model caching dependency for Laravel Enso

2863.2k25](/packages/laravel-enso-rememberable)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)

PHPackages © 2026

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