{"id":15561167,"url":"https://github.com/slydeath/laravel-nested-caching","last_synced_at":"2025-09-10T16:41:11.037Z","repository":{"id":57053455,"uuid":"386184009","full_name":"SlyDeath/laravel-nested-caching","owner":"SlyDeath","description":"Nested Caching for Laravel with caches stack","archived":false,"fork":false,"pushed_at":"2023-06-20T08:21:30.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-16T06:53:37.860Z","etag":null,"topics":["cache","cache-control","laravel","laravel-framework","laravel-package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SlyDeath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-15T06:09:23.000Z","updated_at":"2023-12-04T00:41:23.000Z","dependencies_parsed_at":"2024-11-15T08:04:43.124Z","dependency_job_id":"80e46973-9f34-4f5d-9332-a0cd988391c0","html_url":"https://github.com/SlyDeath/laravel-nested-caching","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.33333333333333337","last_synced_commit":"7a9b6616e5edbdb4c8aa3de3e806c489a8c07e46"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/SlyDeath/laravel-nested-caching","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlyDeath%2Flaravel-nested-caching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlyDeath%2Flaravel-nested-caching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlyDeath%2Flaravel-nested-caching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlyDeath%2Flaravel-nested-caching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SlyDeath","download_url":"https://codeload.github.com/SlyDeath/laravel-nested-caching/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlyDeath%2Flaravel-nested-caching/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274487589,"owners_count":25294566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-control","laravel","laravel-framework","laravel-package","php"],"created_at":"2024-10-02T16:05:50.082Z","updated_at":"2025-09-10T16:41:11.016Z","avatar_url":"https://github.com/SlyDeath.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nested Caching for Laravel with caches stack\n\n[![Latest Stable Version](https://poser.pugx.org/slydeath/laravel-nested-caching/v/stable)](https://packagist.org/packages/slydeath/laravel-nested-caching)\n[![Total Downloads](https://poser.pugx.org/slydeath/laravel-nested-caching/downloads)](https://packagist.org/packages/slydeath/laravel-nested-caching)\n[![License](https://poser.pugx.org/slydeath/laravel-nested-caching/license)](https://packagist.org/packages/slydeath/laravel-nested-caching)\n\n## Minimum requirements\n\n- PHP 7.4\n- Laravel 8\n\n## Installation\n\nAdd package to composer.json:\n\n```bash\ncomposer require slydeath/laravel-nested-caching\n```\n\nOpen `config/app.php` and add the service provider to the array `providers`:\n\n```php\nSlyDeath\\NestedCaching\\NestedCachingServiceProvider::class,\n```\n\nTo place the configuration file, run:\n\n```bash\nphp artisan vendor:publish --provider=\"SlyDeath\\NestedCaching\\NestedCachingServiceProvider\" --tag=config\n```\n\n## How to use?\n\n### Caching any HTML chunk\n\nTo cache any HTML chunk, you just need to pass the caching key to the `@cache` directive fragment:\n\n```html\n@cache('simple-cache')\n\u003cdiv\u003e\n    This is an arbitrary piece of HTML that will be cached\n    using the «simple-cache» key\n\u003c/div\u003e\n@endCache\n```\n\n### Model caching\n\nTo enable model caching support, add the trait to it `NestedCacheable`:\n\n```php\nuse SlyDeath\\NestedCaching\\NestedCacheable;\n\nclass User extends Model\n{\n    use NestedCacheable;\n}\n```\n\nIn the template, to cache a model, you need to pass its instance to the `@cache` directive:\n\n```html\n@cache($user)\n\u003cdiv\u003eApp\\User model caching:\u003c/div\u003e\n\u003cul\u003e\n    \u003cli\u003eName: {{ $user-\u003ename }}\u003c/li\u003e\n    \u003cli\u003eEmail: {{ $user-\u003eemail }}\u003c/li\u003e\n\u003c/ul\u003e\n@endCache\n```\n\n### Caching the model for a specified time\n\nTo cache the model for a certain time, specify the lifetime in minutes as the second parameter:\n\n```html\n@cache($user, 1440)\n\u003cdiv\u003e...\u003c/div\u003e\n@endCache\n ```\n\n#### Updating the «parent»\n\nFor update the cache of the «parent model», we need setup touches:\n\n```php\nuse SlyDeath\\NestedCaching\\NestedCacheable;\n\nclass CarUser extends Model\n{\n    use NestedCacheable;\n\n    // Specifying the parent relations\n    protected $touches = ['user']; \n\n    // Parent relation\n    public function user()\n    {\n        return $this-\u003ebelongsTo(User::class);\n    }\n}\n```\n\nUsage example:\n\n**resources/views/user.blade.php**\n\n```html\n@cache($user)\n\u003csection\u003e\n    \u003ch2\u003eUser's cars {{ $user-\u003ename }}\u003c/h2\u003e\n    \u003cul\u003e\n        @foreach($user-\u003ecars as $car)\n            @include('user-car');\n        @endforeach\n    \u003c/ul\u003e\n\u003c/section\u003e\n@endCache\n```\n\n**resources/views/user-car.blade.php**\n\n```html\n@cache($car)\n\u003cli\u003e{{ $car-\u003ebrand }}\u003c/li\u003e\n@endCache\n```\n\n### Collection caching\n\nExample of caching a collection:\n\n```html\n@cache($users)\n@foreach ($users as $user)\n    @include('user');\n@endforeach\n@endCache\n```\n\n### How to remove stack cache?\n\nJust run this code at bottom of your page:\n\n```php\napp(SlyDeath\\NestedCaching\\CacheStack::class)-\u003eclearCache();\n```\n\n## Workflow with another caches\n\n### How to collect keys?\n\nKeys are automatically collected in `SlyDeath\\NestedCaching\\CacheWrittenListener` if `another-caching` is enabled, \nbut you must save them manually (at the end of executing app) if you want to use them elsewhere:\n\n```php\napp(\\SlyDeath\\NestedCaching\\CacheStack::class)-\u003egetAnotherCaches();\n```\n\n### How to clear the stack of another caches?\n\nJust call`clearAnotherCaches` method:\n\n```php\n app(\\SlyDeath\\NestedCaching\\CacheStack::class)-\u003eclearAnotherCaches();\n```\n\n### How to save keys for different pages?\n\nYou can generate dynamically the cache key (for example from the page id):\n\n```php\napp(\\SlyDeath\\NestedCaching\\CacheStack::class)-\u003esetAnotherKey('my-cache-key-prefix:' . optional($page)-\u003eid)-\u003egetAnotherCaches();\n```\n\n### How to clear the stack of another caches with custom cache key?\n\nJust call`clearAnotherCaches` method and provide the key:\n\n```php\n app(\\SlyDeath\\NestedCaching\\CacheStack::class)-\u003esetAnotherKey('my-cache-key-prefix:' . optional($page)-\u003eid)-\u003eclearAnotherCaches();\n```\n\n## Enable PhpStorm support\n\nGo to the `Settings → PHP → Blade`, then uncheck **Use default settings**. Go to **Directives** tab and press «+» to add\nanother one custom directive:\n\n- Name: `cache`\n- Checkbox **Has parameters** → `true`\n- Prefix: ```\u003c?php if ( ! app('SlyDeath\\NestedCaching\\BladeDirectives')-\u003ecache(```\n- Suffix: ```)) { ?\u003e```\n\nAnd add close directive without parameters:\n\n- Name: `endcache` or `endCache`, whatever you use","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslydeath%2Flaravel-nested-caching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslydeath%2Flaravel-nested-caching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslydeath%2Flaravel-nested-caching/lists"}