PHPackages                             slydeath/laravel5-nested-caching - 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. slydeath/laravel5-nested-caching

ActiveLibrary[Caching](/categories/caching)

slydeath/laravel5-nested-caching
================================

Nested Caching для Laravel 5.8

3.2(6y ago)11.0kMITPHP

Since Mar 7Pushed 4y ago2 watchersCompare

[ Source](https://github.com/SlyDeath/laravel5-nested-caching)[ Packagist](https://packagist.org/packages/slydeath/laravel5-nested-caching)[ RSS](/packages/slydeath-laravel5-nested-caching/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)DependenciesVersions (7)Used By (0)

### WARNING!!!

[](#warning)

This package no longer maintained, please, use  instead

Nested Caching для Laravel 5
============================

[](#nested-caching-для-laravel-5)

[![Latest Stable Version](https://camo.githubusercontent.com/4e3edcd45b6687cda19d84c12b5bfedf6af79a956103f8375945ef6580f40e5f/68747470733a2f2f706f7365722e707567782e6f72672f736c7964656174682f6c61726176656c352d6e65737465642d63616368696e672f762f737461626c65)](https://packagist.org/packages/slydeath/laravel5-nested-caching)[![Total Downloads](https://camo.githubusercontent.com/6bbce5a4f37c017a3cb85d22147390c60aadd48ef5bd1d43ab6aa2fc75ee819d/68747470733a2f2f706f7365722e707567782e6f72672f736c7964656174682f6c61726176656c352d6e65737465642d63616368696e672f646f776e6c6f616473)](https://packagist.org/packages/slydeath/laravel5-nested-caching)[![License](https://camo.githubusercontent.com/2612634d324bb782d9385408b3f6afb4fdacf795bc742b6116a83b8a711a1bb9/68747470733a2f2f706f7365722e707567782e6f72672f736c7964656174682f6c61726176656c352d6e65737465642d63616368696e672f6c6963656e7365)](https://packagist.org/packages/slydeath/laravel5-nested-caching)

Версии
------

[](#версии)

Версия 3.\* для Laravel 5.8, для 5.6-5.7 использовать релиз 2.\*

Установка
---------

[](#установка)

Добавить пакет в composer.json:

```
composer require slydeath/laravel5-nested-caching
```

Открыть `config/app.php` и добавить сервис провайдера в массив `providers`:

```
SlyDeath\NestedCaching\NestedCachingServiceProvider::class,
```

Для размещения файла конфигурации выполнить:

```
php artisan vendor:publish --provider="SlyDeath\NestedCaching\NestedCachingServiceProvider" --tag=config
```

Для работы необходимы кэш-драйверы поддерживающие тэгирование - это **Memcached** или **Redis**.

В `.env` файле для **Memcached** указываем:

```
CACHE_DRIVER=memcached

```

для **Redis**:

```
CACHE_DRIVER=redis

```

Так же для работы **Redis** необходимо установить пакет `predis/predis`:

```
composer require predis/predis
```

Как использовать?
-----------------

[](#как-использовать)

### Кэширование любого отрезка html

[](#кэширование-любого-отрезка-html)

Чтобы закэшировать любой произвольный кусок HTML, нужн опросто передать в директиву `@cache` ключ для кэширования фрагмента:

```
@cache('simple-cache')
    Это произвольный кусок HTML который будет закэширован по ключу "simple-cache"
@endcache
```

### Кэширование моделей

[](#кэширование-моделей)

Добавить в класс модели, которая будет кэшироваться, трейт `NestedCacheable`:

```
use SlyDeath\NestedCaching\NestedCacheable;

class User extends Model
{
    use NestedCacheable;
}
```

В шаблоне, для кэширования модели, необходимо передать в директиву `@cache` её инстанс:

```
@cache($user)
    Кэширование модели App\User:

        Имя: {{ $user->name }}
        Email: {{ $user->email }}

@endcache
```

### Кэширование модели на указанное время

[](#кэширование-модели-на-указанное-время)

Для кэширования модели на определённое время, указываем вторым параметром время жизни в минутах:

```
@cache($user, 1440)
    ...
@endcache
```

#### Обновление "родителя"

[](#обновление-родителя)

Чтобы при обновлении модели так же сбрасывался кэш "модели-родителя", необходимо обновлять поле `updated_at` у модели-родителя:

```
use SlyDeath\NestedCaching\NestedCacheable;

class CarUser extends Model
{
    use NestedCacheable;

    protected $touches = ['user']; // Указываем родителя

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
```

Пример использования:

**resources/views/user.blade.php**

```
@cache($user)

        Автомобили пользователя {{ $user->name }}

            @foreach($user->cars as $car)
                @include('user-car');
            @endforeach

@endcache
```

**resources/views/user-car.blade.php**

```
@cache($car)
    {{ $car->brand }}
@endcache
```

### Кэширование коллекций

[](#кэширование-коллекций)

Пример кэширования коллекции:

```
@cache($users)

    @foreach ($users as $user)
        @include('user');
    @endforeach

@endcache
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

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

Recently: every ~208 days

Total

6

Last Release

2460d ago

Major Versions

1.2 → 2.02018-11-26

2.0 → 3.02019-03-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/3569b9f649cad0bd9adf91a6bb74b35ff58108505154ab8598f92108ca6218e8?d=identicon)[SlyDeath](/maintainers/SlyDeath)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/slydeath-laravel5-nested-caching/health.svg)

```
[![Health](https://phpackages.com/badges/slydeath-laravel5-nested-caching/health.svg)](https://phpackages.com/packages/slydeath-laravel5-nested-caching)
```

###  Alternatives

[beryllium/cachebundle

Provides an interface to Memcache for Symfony2 applications

32136.0k](/packages/beryllium-cachebundle)

PHPackages © 2026

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