{"id":22900313,"url":"https://github.com/vectorial1024/laravel-cache-evict","last_synced_at":"2025-05-08T01:11:49.503Z","repository":{"id":259662201,"uuid":"806723790","full_name":"Vectorial1024/laravel-cache-evict","owner":"Vectorial1024","description":"Efficiently remove expired cache data in Laravel.","archived":false,"fork":false,"pushed_at":"2025-04-12T11:54:13.000Z","size":170,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-08T01:11:41.135Z","etag":null,"topics":["cache","laravel","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/vectorial1024/laravel-cache-evict","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/Vectorial1024.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":["Vectorial1024"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2024-05-27T19:06:50.000Z","updated_at":"2025-04-12T11:54:17.000Z","dependencies_parsed_at":"2024-10-27T07:19:28.141Z","dependency_job_id":"f596ea49-9d45-4514-b3fa-5f1839572ca9","html_url":"https://github.com/Vectorial1024/laravel-cache-evict","commit_stats":null,"previous_names":["vectorial1024/laravel-cache-evict"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Flaravel-cache-evict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Flaravel-cache-evict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Flaravel-cache-evict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Flaravel-cache-evict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vectorial1024","download_url":"https://codeload.github.com/Vectorial1024/laravel-cache-evict/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978779,"owners_count":21834917,"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":["cache","laravel","php"],"created_at":"2024-12-14T01:18:56.490Z","updated_at":"2025-05-08T01:11:49.487Z","avatar_url":"https://github.com/Vectorial1024.png","language":"PHP","funding_links":["https://github.com/sponsors/Vectorial1024"],"categories":[],"sub_categories":[],"readme":"# laravel-cache-evict\n[![Packagist License][packagist-license-image]][packagist-url]\n[![Packagist Version][packagist-version-image]][packagist-url]\n[![Packagist Downloads][packagist-downloads-image]][packagist-stats-url]\n[![PHP Dependency Version][php-version-image]][packagist-url]\n[![GitHub Actions Workflow Status][php-build-status-image]][github-actions-url]\n[![GitHub Repo Stars][github-stars-image]][github-repo-url]\n\nEfficiently remove expired cache data in Laravel.\n\n## Situation\nAs of writing, several Laravel cache drivers do not have automatic removal of expired cached items:\n\n- `file`\n- `database`\n\n### Why is it a problem?\nUsing any of the above cache drivers without regularly removing the expired items (aka \"key eviction\" in Redis) can result in storage overload, especially when you are creating a lot of temporary items with random keys.\n\nThe `cache:clear` command from Laravel works, but might not be the thing you want. It does not check item expiry (it removes everything), and also clears the Laravel framework cache (e.g. `/bootstrap/cache/*`), which can be especially problematic when you are using the `file` cache driver (consider a case: cache items are created by the `www-data` user but `/bootstrap/cache/*` is owned by the `ubuntu` user).\n\nIn this case, this library can help you remove only the expired items in your cache. See below sections for more details.\n\nThis library is designed to be memory efficient and (for `database` caches) non-blocking, so even if there are a lot of items in the cache (e.g. you are running this for the first time to deal with an oversized cache), it can still run reasonably well.\n\n## Install\nvia Composer:\n\n```sh\ncomposer require vectorial1024/laravel-cache-evict\n```\n\nSuggestions:\n- (Optional) `ext-intl` allows using Laravel's own `Number::fileSize()` for size reporting\n\n### Supported cache types\nThe following cache drivers from `cache.php` are currently supported:\n- `database`\n- `file`\n\nSome drivers (e.g. `memcached`, `redis`) will never be supported because they have their own item eviction mechanisms; use those features instead of this library!\n\nCustom eviction strategies can be defined for other cache drivers that does not have their own eviction mechanisms (see FAQ section).\n\n### Change log\nPlease see `CHANGELOG.md`.\n\n## Usage\n\nYou may run this in the command line:\n\n```sh\n# evicts the default cache in your Laravel app\nphp artisan cache:evict\n\n# you may also specify the cache to clear; e.g. the file cache defined in cache.php:\nphp artisan cache:evict file\n```\n\nOr, you may put this into your console kernel schedule:\n\n```php\nuse Vectorial1024\\LaravelCacheEvict\\CacheEvictCommand;\n\n// note: because this command may have long running time, it is strongly recommended to run this command in the background\n// this avoids accidentally delaying other scheduled tasks\n\n// evicts the default cache in your Laravel app\nSchedule::command(CacheEvictCommand::class)-\u003edaily()-\u003erunInBackground();\n\n// you may also specify the cache to clear; e.g. the file cache defined in cache.php:\nSchedule::command(CacheEvictCommand::class, ['target' =\u003e 'file'])-\u003edaily()-\u003erunInBackground();\n```\n\n### The relationship with `cache.php`\nThis library checks the cache *name* (not *driver*!) inside `cache.php` to determine which cache to clear. This means, if you have the following `cache.php` ...\n\n```php\n[\n    'stores' =\u003e [\n        'local_store' =\u003e [\n            'driver' =\u003e 'file',\n            // other config...\n        ],\n\n        'another_store' =\u003e [\n            'driver' =\u003e 'file',\n            // other config...\n        ],\n    ],\n]\n```\n\n... and you run the command like this ...\n\n```sh\nphp artisan cache:evict local_store\n```\n\n... then, you will only evict the `local_store` cache. The `another_store` cache is unaffected by this command (assuming both are using separate directories, of course).\n\n## Testing\nPHPUnit (using `orchestra/testbench`) via Composer:\n\n```sh\ncomposer run-script test\n```\n\n## Frequently-asked questions (FAQ)\n\n### How to define custom eviction strategies?\nYou can do so inside your Laravel service provider. Simply do the following:\n\n```php\npublic function boot()\n{\n    // register a handler for a specific cache driver\n    // YourEvictStrategy extends Vectorial1024\\LaravelCacheEvict\\AbstractEvictStrategy\n    CacheEvictStrategies::registerDriverStrategy('your_driver_name', YourEvictStrategy::class);\n\n    // or, register that a specific cache driver should not be handled because it has its own handler already\n    CacheEvictStrategies::registerDriverRefusedBecauseFeatureExists('self_managed_driver_name');\n}\n```\n\n### Will this library help me reclaim `database` disk spaces?\nNo, but if you are using this library regularly to evict expired items, then you do not need to worry about reclaiming free space. For more details, talk with a system admin/database specialist.\n\n[packagist-url]: https://packagist.org/packages/vectorial1024/laravel-cache-evict\n[packagist-stats-url]: https://packagist.org/packages/vectorial1024/laravel-cache-evict/stats\n[github-repo-url]: https://github.com/Vectorial1024/laravel-cache-evict\n[github-actions-url]: https://github.com/Vectorial1024/laravel-cache-evict/actions/workflows/php.yml\n\n[packagist-license-image]: https://img.shields.io/packagist/l/vectorial1024/laravel-cache-evict?style=plastic\n[packagist-version-image]: https://img.shields.io/packagist/v/vectorial1024/laravel-cache-evict?style=plastic\n[packagist-downloads-image]: https://img.shields.io/packagist/dm/vectorial1024/laravel-cache-evict?style=plastic\n[php-version-image]: https://img.shields.io/packagist/dependency-v/vectorial1024/laravel-cache-evict/php?style=plastic\u0026label=PHP\n[php-build-status-image]: https://img.shields.io/github/actions/workflow/status/Vectorial1024/laravel-cache-evict/php.yml?style=plastic\n[github-stars-image]: https://img.shields.io/github/stars/vectorial1024/laravel-cache-evict\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectorial1024%2Flaravel-cache-evict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvectorial1024%2Flaravel-cache-evict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectorial1024%2Flaravel-cache-evict/lists"}