PHPackages                             ulex/cached-repositories - 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. ulex/cached-repositories

ActiveProject[Caching](/categories/caching)

ulex/cached-repositories
========================

Cached Repositories - A simple Laravel package

2.1.0(4y ago)0680MITPHPPHP ^7.0

Since Dec 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/alexpilavakis/cached-repositories)[ Packagist](https://packagist.org/packages/ulex/cached-repositories)[ RSS](/packages/ulex-cached-repositories/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (20)Used By (0)

Centralize and cache you application's queries
==============================================

[](#centralize-and-cache-you-applications-queries)

Documentation, Installation, and Usage Instructions
---------------------------------------------------

[](#documentation-installation-and-usage-instructions)

First, install the package via Composer:

```
composer require ulex/cached-repositories

```

---

 Service Provider
------------------

[](#-service-provider-)

### For Laravel

[](#for-laravel)

You should publish the RepositoriesServiceProvider:

```
php artisan vendor:publish --provider="Ulex\CachedRepositories\RepositoriesServiceProvider" --tag=config
```

Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file: Laravel

```
'providers' => [
// ...
Ulex\CachedRepositories\RepositoriesServiceProvider::class,
];
```

### For Lumen

[](#for-lumen)

In your `bootstrap/app.php`:

1. Register the provider

```
$app->register(Ulex\CachedRepositories\RepositoriesServiceProvider::class);
```

2. Register config

```
$app->configure('cached-repositories');
```

---

 Config
--------

[](#-config-)

If config file `cached-repositories.php` was not published copy it to config folder with:

```
cp vendor/ulex/cached-repositories/config/cached-repositories.php config/cached-repositories.php

```

 Create Repository, Interface, Decorator for a Model
-----------------------------------------------------

[](#-create-repository-interface-decorator-for-a-model-)

Run the following php artisan command where the argument is your Model name (example Post):

```
php artisan make:repository Post --all
```

Expected Result:

```
Repository created successfully.
Interface created successfully.
Decorator created successfully.
Add Model in `models` array in config/cached-repositories.php
```

The following folders will be created in your `app/Repositories` folder (if they don't exist):

```
Decorators
Eloquent
Interfaces
```

As seen in the result remember to add the Model in `config/cached-repositories.php` :

```
...
'models' => [
        'User' => App\Models\User::class,
        'Post' => App\Models\Post::class,
]
...
```

How to use
----------

[](#how-to-use)

This package provides an abstract structure that uses the Repository design pattern with caching decorators for you application.

Once installed you can create Repositories for your models that cache the data from your queries. EloquentRepository is provided and ready to use. Follow the same principle for any data resource you have on your application.

```
# Example when injecting to a controller

public function __construct(UserRepositoryInterface $userRepository)
{
    $this->userRepository = $userRepository;
}

...

public function get($name)
{
    //retrieve from db and then cache the result
    $user = $this->userRepository->getBy('name', $userName);
    //retrieve straight from db, don't cache
    $user = $this->userRepository->fromDb()->getBy('name', $userName);
}
```

Extending a model's CachingDecorator
------------------------------------

[](#extending-a-models-cachingdecorator)

For GET functions use `remember` function the same way as in the abstract CachingDecorator. This will ensure that this function is cached properly.

#### UserCachingDecorator.php

[](#usercachingdecoratorphp)

```
public function getUserInfo($user_id)
{
    return $this->remember(__FUNCTION__, func_get_args());
}
```

**Note:** Remember to add the cache invalidation of the new function by extending flushGetKeys in the model's CachingDecorator.

```
public function flushGetKeys($model, $attributes = null)
{
    $user_id = $model->user_id;
    $key = $this->key('getUserInfo', compact('user_id'));
    parent::flushGetKeys($model, $attributes);
}
```

#### UserRepository.php

[](#userrepositoryphp)

Add the query in the model's repository

```
public function getUserInfo($user_id)
{
    return $this->model->query()
        ->where('user_id', '=', $user_id)
        ->whereNotNull('something')->get();
}
```

Contributing
------------

[](#contributing)

This package is mostly based on [Jeffrey Way](https://twitter.com/jeffrey_way)'s awesome [Laracasts](https://laracasts.com) lessons when using the repository design pattern on [Laravel From Scratch](https://laracasts.com/series/laravel-6-from-scratch) series.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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

Recently: every ~44 days

Total

18

Last Release

1645d ago

Major Versions

1.2.1 → 2.0.02021-04-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c0d1398d65cb4a1f7a8665a941c8eef9a72c2415b460eea0c2a9cce19898361?d=identicon)[alexpilavakis](/maintainers/alexpilavakis)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/ulex-cached-repositories/health.svg)

```
[![Health](https://phpackages.com/badges/ulex-cached-repositories/health.svg)](https://phpackages.com/packages/ulex-cached-repositories)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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