{"id":33997301,"url":"https://github.com/innoge/laravel-policy-soft-cache","last_synced_at":"2025-12-13T08:56:25.872Z","repository":{"id":62594240,"uuid":"560532922","full_name":"InnoGE/laravel-policy-soft-cache","owner":"InnoGE","description":"Enhance Laravel's authorization efficiency with soft caching for policy checks—boosting performance without affecting concurrent request integrity.","archived":false,"fork":false,"pushed_at":"2025-04-15T12:42:54.000Z","size":43,"stargazers_count":22,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-17T12:42:05.352Z","etag":null,"topics":["cache","laravel","php","policy"],"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/InnoGE.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2022-11-01T17:54:56.000Z","updated_at":"2025-10-08T03:25:28.000Z","dependencies_parsed_at":"2023-02-09T07:02:06.649Z","dependency_job_id":"ba749f2a-8105-41a6-aa82-b886b7dd29a9","html_url":"https://github.com/InnoGE/laravel-policy-soft-cache","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"d19db37ed8cd06bd2630c9737ad0b7855d13303a"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/InnoGE/laravel-policy-soft-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InnoGE%2Flaravel-policy-soft-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InnoGE%2Flaravel-policy-soft-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InnoGE%2Flaravel-policy-soft-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InnoGE%2Flaravel-policy-soft-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InnoGE","download_url":"https://codeload.github.com/InnoGE/laravel-policy-soft-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InnoGE%2Flaravel-policy-soft-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702865,"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-12-13T02:00:09.769Z","response_time":147,"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","laravel","php","policy"],"created_at":"2025-12-13T08:56:24.597Z","updated_at":"2025-12-13T08:56:25.856Z","avatar_url":"https://github.com/InnoGE.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Policy Soft Cache Package\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/innoge/laravel-policy-soft-cache.svg?style=flat-square)](https://packagist.org/packages/innoge/laravel-policy-soft-cache)\n[![Tests](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/run-tests.yml/badge.svg)](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/run-tests.yml)\n[![Fix PHP code style issues](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/fix-php-code-style-issues.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/innoge/laravel-policy-soft-cache.svg?style=flat-square)](https://packagist.org/packages/innoge/laravel-policy-soft-cache)\n\nOptimize your Laravel application's performance with soft caching for policy checks. This package caches policy invocations to prevent redundant checks within the same request lifecycle, enhancing your application's response times.\n\n## Requirements\n\nThis package is compatible with ```Laravel 9, 10, 11, 12```, and PHP \u003e= 8.1.\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require innoge/laravel-policy-soft-cache\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --provider=\"Innoge\\LaravelPolicySoftCache\\LaravelPolicySoftCacheServiceProvider\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n    /*\n     * When enabled, the package will cache the results of all Policies in your Laravel application\n     */\n    'cache_all_policies' =\u003e env('CACHE_ALL_POLICIES', true),\n];\n```\n\nYou can also use `CACHE_ALL_POLICIES` in your `.env` file to change it.\n```.dotenv\nCACHE_ALL_POLICIES=false\n```\n\n## Usage\n\nBy default, this package caches all policy calls of your entire application. You can disable this behavior by setting the ```cache_all_policies```configuration to false. Now you can specify which Policy classes should be soft cached and which not. If you want your policy to be cached, add the ```Innoge\\LaravelPolicySoftCache\\Contracts\\SoftCacheable``` interface.\n\nFor Example:\n\n```\nuse Innoge\\LaravelPolicySoftCache\\Contracts\\SoftCacheable;\n\nclass UserPolicy implements SoftCacheable\n{\n    ...\n}\n```\n\n## Clearing the cache\nSometimes you want to clear the policy cache after model changes. You can call the ```Innoge\\LaravelPolicySoftCache::flushCache();``` method.\n\n## Known Issues\n### Gate::before and Service Provider Load Order\n\nWhen the `innoge/laravel-policy-soft-cache` package is installed in an application that utilizes `Gate::before`, typically defined in the `AuthServiceProvider`, a conflict may arise due to the order in which service providers are loaded.\n\n#### Resolution Steps\nTo resolve this issue, follow these steps:\n\n1. **Manual Service Provider Registration**: Add `\\Innoge\\LaravelPolicySoftCache\\LaravelPolicySoftCacheServiceProvider::class` to the end of the `providers` array in your `config/app.php`. This manual registration ensures that the `LaravelPolicySoftCacheServiceProvider` loads after all other service providers, including `AuthServiceProvider`.\n\n    ```php\n    'providers' =\u003e [\n        // Other Service Providers\n\n        \\Innoge\\LaravelPolicySoftCache\\LaravelPolicySoftCacheServiceProvider::class,\n    ],\n    ```\n\n2. **Disable Auto-Discovery for the Package**: To prevent Laravel's auto-discovery mechanism from automatically loading the service provider, add `innoge/laravel-policy-soft-cache` to the `dont-discover` array in your `composer.json`. This step is crucial for maintaining the manual load order.\n\n    ```json\n    \"extra\": {\n        \"laravel\": {\n            \"dont-discover\": [\"innoge/laravel-policy-soft-cache\"]\n        }\n    },\n    ```\n\n3. **Reinstall Dependencies**: After updating your `composer.json`, run `composer install` to apply the changes. This step is necessary for the changes to take effect.\n\n    ```bash\n    composer install\n    ```\n\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](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Tim Geisendörfer](https://github.com/geisi)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finnoge%2Flaravel-policy-soft-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finnoge%2Flaravel-policy-soft-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finnoge%2Flaravel-policy-soft-cache/lists"}