{"id":20806488,"url":"https://github.com/elipzis/laravel-cacheable-model","last_synced_at":"2025-05-16T07:04:01.547Z","repository":{"id":60859668,"uuid":"505877142","full_name":"elipZis/laravel-cacheable-model","owner":"elipZis","description":"⚙️ Automatically cache Laravel Eloquent models by queries","archived":false,"fork":false,"pushed_at":"2025-05-12T13:15:48.000Z","size":218,"stargazers_count":133,"open_issues_count":0,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-12T14:42:13.554Z","etag":null,"topics":["cache","database","eloquent","laravel","memcached","model","php","redis"],"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/elipZis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"elipZis"}},"created_at":"2022-06-21T14:25:58.000Z","updated_at":"2025-05-12T13:15:45.000Z","dependencies_parsed_at":"2024-04-29T15:01:58.820Z","dependency_job_id":"2b56bc27-5520-4313-9ddf-edbc4822968f","html_url":"https://github.com/elipZis/laravel-cacheable-model","commit_stats":{"total_commits":47,"total_committers":3,"mean_commits":"15.666666666666666","dds":0.4042553191489362,"last_synced_commit":"e6b72ec20aef0da842c9076ee22ff28a06460bb9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Flaravel-cacheable-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Flaravel-cacheable-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Flaravel-cacheable-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Flaravel-cacheable-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elipZis","download_url":"https://codeload.github.com/elipZis/laravel-cacheable-model/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485053,"owners_count":22078767,"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","database","eloquent","laravel","memcached","model","php","redis"],"created_at":"2024-11-17T19:20:20.535Z","updated_at":"2025-05-16T07:04:01.524Z","avatar_url":"https://github.com/elipZis.png","language":"PHP","readme":"# Automatically cache Laravel Eloquent models by queries\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/elipzis/laravel-cacheable-model.svg?style=flat-square)](https://packagist.org/packages/elipzis/laravel-cacheable-model)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/elipzis/laravel-cacheable-model/run-tests.yml?branch=main)](https://github.com/elipzis/laravel-cacheable-model/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/elipzis/laravel-cacheable-model/php-cs-fixer.yml?branch=main)](https://github.com/elipzis/laravel-cacheable-model/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/elipzis/laravel-cacheable-model.svg?style=flat-square)](https://packagist.org/packages/elipzis/laravel-cacheable-model)\n\nEasy and automatic select-query caching for your Eloquent models!\n\n* Get cached query results and reduce your database load automatically\n* Configure TTL, prefixes, unique-queries etc.\n* No manual cache calls needed\n* Automated cache flush in case of updates, inserts or deletions\n\nYou can make any Eloquent model cacheable by adding the trait\n\n```php\n...\nuse ElipZis\\Cacheable\\Models\\Traits\\Cacheable;\n...\n\nclass YourModel extends Model {\n\n    use Cacheable;\n    ... \n```\n\nand leverage the power of a Redis, memcached or other caches.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require elipzis/laravel-cacheable-model\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"cacheable-model-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\n    //Default values for the Cacheable trait - Can be overridden per model\n    return [\n        //How long should cache last in general?\n        'ttl' =\u003e 300,\n        //By what should cache entries be prefixed?\n        'prefix' =\u003e 'cacheable',\n        //What is the identifying, unique column name?\n        'identifier' =\u003e 'id',\n        //Do you need logging?\n        'logging' =\u003e [\n            'channel' =\u003e null, //Which channel should be used?\n            'enabled' =\u003e false,\n            'level' =\u003e 'debug',\n        ],\n    ];\n```\n\n## Usage\n\nMake your model cacheable by adding the trait:\n\n```php\n...\nuse ElipZis\\Cacheable\\Models\\Traits\\Cacheable;\n...\n\nclass YourModel extends Model {\n\n    use Cacheable;\n    ... \n```\n\nand then just use your normal model query, for example\n\n```php\nYourModel::query()-\u003eget();\n```\n\n```php\nYourModel::query()-\u003ewhere('field', 'test')-\u003efirst();\n```\n\n```php\nYourModel::query()-\u003einsert([...]);\n```\n\nThe package overrides the QueryBuilder and scans for the same queries to capture and return the cached values.\n\nYou do not need to do anything else but just use your model as you would and leverage the power of cached entries! \n\n### Configuration\n\nThe following configuration can be overridden per model\n\n```php\npublic function getCacheableProperties(): array {\n    return [\n        'ttl' =\u003e 300,\n        'prefix' =\u003e 'cacheable',\n        'identifier' =\u003e 'id',\n        'logging' =\u003e [\n            'channel' =\u003e 'anotherChannel',\n            'enabled' =\u003e false,\n            'level' =\u003e 'debug',\n        ],\n    ];\n}\n```\n\n### Disable cache\n\nDepending on your cache and database performance, you might like to retrieve a query without caching sometimes:\n\n```php\nYourModel::query()-\u003ewithoutCache()-\u003eget();\n```\n\n### Flush cache\n\nIf your data is updated outside of this package, you can flush it yourself by calling:\n\n```php\nYourModel::query()-\u003eflushCache();\n```\n\n### Note on using caching\n\nThis package overrides the native QueryBuilder and is capturing every database query, therefore it imposes a load and\nperformance burden.\n\nIf you use caching intensively on a model, this package and its use can help. If an entity is permanently changing, it\nwon't make sense to make it `Cacheable`.\n\nIt is recommended to only make models `Cacheable` which have a reasonable caching time in your system. Do not use the\ntrait on any other or all models out of the box, but think about where it makes sense.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.\n\n## Credits\n\n- [elipZis GmbH](https://elipZis.com)\n- [NeA](https://github.com/nea)\n- [All Contributors](https://github.com/elipZis/laravel-cacheable-model/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":["https://github.com/sponsors/elipZis"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipzis%2Flaravel-cacheable-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felipzis%2Flaravel-cacheable-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipzis%2Flaravel-cacheable-model/lists"}