{"id":22337302,"url":"https://github.com/handmadeweb/statamic-multi-cacher","last_synced_at":"2025-03-26T08:22:58.239Z","repository":{"id":62514393,"uuid":"389230373","full_name":"HandmadeWeb/statamic-multi-cacher","owner":"HandmadeWeb","description":"Statamic Multi Cacher is a caching strategy that allows you to specify multiple caching strategies.","archived":false,"fork":false,"pushed_at":"2021-07-27T22:02:08.000Z","size":64,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T12:44:27.427Z","etag":null,"topics":[],"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/HandmadeWeb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-25T01:03:33.000Z","updated_at":"2022-03-25T03:53:47.000Z","dependencies_parsed_at":"2022-11-02T13:15:43.172Z","dependency_job_id":null,"html_url":"https://github.com/HandmadeWeb/statamic-multi-cacher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Fstatamic-multi-cacher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Fstatamic-multi-cacher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Fstatamic-multi-cacher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Fstatamic-multi-cacher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HandmadeWeb","download_url":"https://codeload.github.com/HandmadeWeb/statamic-multi-cacher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245615732,"owners_count":20644518,"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","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":[],"created_at":"2024-12-04T06:09:29.962Z","updated_at":"2025-03-26T08:22:58.217Z","avatar_url":"https://github.com/HandmadeWeb.png","language":"PHP","readme":"[![Latest Version on Packagist](https://img.shields.io/packagist/v/handmadeweb/statamic-multi-cacher.svg?style=flat-square)](https://packagist.org/packages/handmadeweb/statamic-multi-cacher)\n[![Total Downloads](https://img.shields.io/packagist/dt/handmadeweb/statamic-multi-cacher.svg?style=flat-square)](https://packagist.org/packages/handmadeweb/statamic-multi-cacher)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.md)\n[![Run Tests](https://github.com/handmadeweb/statamic-multi-cacher/actions/workflows/tests.yml/badge.svg)](https://github.com/handmadeweb/statamic-multi-cacher/actions/workflows/tests.yml)\n![Statamic v3.1](https://img.shields.io/badge/Statamic-3.1+-FF269E?style=flat-square)\n\nStatamic Multi Cacher is a caching strategy \"redirector\" of sorts, it can be used to provide different caching strategies based on your own logic.\n\nAn example of this could be to bypass/disable the cache for super admins and serve the `half` strategy to everyone else.\n\n## THIS IS A BETA\nPlease be aware that it is not recommended to use this in production just yet.\n\n## Requirements\n* Statamic 3.1 or higher\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require handmadeweb/statamic-multi-cacher\n```\n\n## Usage\n\nFirst add the strategy to your `static_cache` config\n\n```php\n'strategies' =\u003e [\n\n    'half' =\u003e [\n        'driver' =\u003e 'application',\n        'expiry' =\u003e null,\n    ],\n\n    'full' =\u003e [\n        'driver' =\u003e 'file',\n        'path' =\u003e public_path('static'),\n        'lock_hold_length' =\u003e 0,\n    ],\n\n    'multi' =\u003e [\n        'driver' =\u003e 'multi-cacher',\n    ],\n],\n```\n\nThen specify the name of the strategies that you want to be available to the `multi-cacher`\n```php\n'multi' =\u003e [\n    'driver' =\u003e 'multi-cacher',\n    'strategies' =\u003e [\n        'half',\n        'full',\n    ],\n],\n```\n\nThen update the `static_cache` strategy at the top of the configuration to:\n```php\n'strategy' =\u003e 'multi',\n```\n\nIt is important to note, that if strategies are omitted or are empty, then the `multi-cacher` strategy will default to `null`.\nThe `null` strategy will always be available for selection, so you don't need to add it to your strategies section.\n\nIf you don't override the `CacheSelector` which is `\\HandmadeWeb\\StatamicMultiCacher\\CacheSelector` then the first strategy will always be used, In the above example this would be `half`.\n\nOverriding can be done by extending the `CacheSelector` class like so:\n```php\n\u003c?php\n\nnamespace App\\Cachers;\n\nuse Illuminate\\Support\\Facades\\Auth;\nuse HandmadeWeb\\StatamicMultiCacher\\CacheSelector;\n\nclass MyMultiCacher extends CacheSelector\n{\n    public function selectCacher()\n    {\n        // Disable cache for super users.\n        if(Auth::check() \u0026\u0026 Auth::user()-\u003eisSuper()){\n            return $this-\u003emultiCacher()-\u003ecachers()-\u003eget('null');\n        }\n\n        // Cache everyone else with the half strategy.\n        return $this-\u003emultiCacher()-\u003ecachers()-\u003eget('half');\n    }\n}\n```\n\nAnd then updating your `static_cache` configuration to be as follows:\n```php\n'multi' =\u003e [\n    'driver' =\u003e 'multi-cacher',\n    'selector' =\u003e \\App\\Cachers\\MyMultiCacher::class,\n    'strategies' =\u003e [\n        'half',\n    ],\n],\n```\n\n## Changelog\n\nPlease see [CHANGELOG](https://github.com/handmadeweb/statamic-multi-cacher/blob/main/CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/handmadeweb/statamic-multi-cacher/blob/main/CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Handmade Web \u0026 Design](https://github.com/handmadeweb)\n- [Michael Rook](https://github.com/michaelr0)\n- [All Contributors](https://github.com/handmadeweb/statamic-multi-cacher/graphs/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/handmadeweb/statamic-multi-cacher/blob/main/LICENSE.md) for more information.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhandmadeweb%2Fstatamic-multi-cacher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhandmadeweb%2Fstatamic-multi-cacher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhandmadeweb%2Fstatamic-multi-cacher/lists"}