{"id":18724508,"url":"https://github.com/area17/edge-flush","last_synced_at":"2025-04-12T15:31:55.634Z","repository":{"id":62354192,"uuid":"389768266","full_name":"area17/edge-flush","owner":"area17","description":"EdgeFlush - CDN Cache Control and Invalidation","archived":false,"fork":false,"pushed_at":"2024-09-26T16:47:58.000Z","size":611,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"1.x","last_synced_at":"2025-04-10T07:16:23.768Z","etag":null,"topics":["cache","cdn","hacktoberfest","laravel","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/area17.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":"area17"}},"created_at":"2021-07-26T21:06:38.000Z","updated_at":"2023-01-31T01:52:44.000Z","dependencies_parsed_at":"2024-09-10T12:04:19.402Z","dependency_job_id":"d3626c44-c2c9-4c9c-acf0-8e61e45b8e03","html_url":"https://github.com/area17/edge-flush","commit_stats":{"total_commits":262,"total_committers":3,"mean_commits":87.33333333333333,"dds":0.4732824427480916,"last_synced_commit":"6ec56418d37853b63c3a19ea7e1bae974346cf13"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/area17%2Fedge-flush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/area17%2Fedge-flush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/area17%2Fedge-flush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/area17%2Fedge-flush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/area17","download_url":"https://codeload.github.com/area17/edge-flush/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589710,"owners_count":21129668,"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","cdn","hacktoberfest","laravel","php"],"created_at":"2024-11-07T14:06:53.921Z","updated_at":"2025-04-12T15:31:54.641Z","avatar_url":"https://github.com/area17.png","language":"PHP","funding_links":["https://github.com/sponsors/area17"],"categories":[],"sub_categories":[],"readme":"# EdgeFlush\n\n\u003c!--\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/area17/edge-flush.svg?style=flat-square)](https://packagist.org/packages/area17/edge-flush)\n--\u003e\n[![GitHub PHPUnit Action Status](https://img.shields.io/github/workflow/status/area17/edge-flush/phpunit?label=PHPUnit)](https://github.com/area17/edge-flush/actions?query=workflow%3Aphpunit+branch%3A1.x)\n[![GitHub PHPStan Action Status](https://img.shields.io/github/workflow/status/area17/edge-flush/phpstan?label=PHPStan)](https://github.com/area17/edge-flush/actions?query=workflow%phpstan+branch%3A1.x)\n\u003c!--\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/area17/edge-flush/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/area17/edge-flush/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3A1.x)\n[![Total Downloads](https://img.shields.io/packagist/dt/area17/edge-flush.svg?style=flat-square)](https://packagist.org/packages/area17/edge-flush)\n--\u003e\n\nEdgeFlush is Laravel package intended to help developers manage CDN granular caching and invalidations. Having Akamai, CloudFront (or any other CDN) in front of a website, data modification usually forces us to bust the whole cache, leading to a website slow (for the first users) until the whole cache is rebuilt, and if the \"first user\" is Google Bot, for example, this can also impact on your website's rank. This pacakge aims to do invalidations granularly.\n\n## Feature list\n\n- Granular invalidation: this package will create a collection of all models that impacts one page and when one of those models change, all pages that had that model rendered in previous requests will be purged from CDN.\n- Granular control of Cache-Control headers: you will be able to configure it differently per request, telling the CDN to store some pages for one week and others for 5 seconds, for example.\n- Single [Akamai Edge Cache Tag](#akamai-edge-cache-tags) relating to all models touched by a page render.\n- Define different strategies for Cache-Control: web pages may have a different cache strategy than api endpoints.\n- Prevents from caching pages containing forms.\n- Caches only frontend pages, leaving the CMS uncashed, if needed.\n- [Re-warm](#rewarming-cache) pages purged from cache.\n- Strip cookies from cachable responses.\n- Disable caching for some pages using a middlware.\n- Define HTTP methods that allow caching or not: cache GET but not POST.\n- Define HTTP response status codes that allow caching or not: Cache 200 and 301 but not 400+ status codes.\n- Define what routes can and cannot be cached by CDN.\n- Define what type of responses can be cached: cache Response but not JsonResponse, for example.\n- Define what Model classes can be cached or not.\n- Remember what pages have been cached and command your CDN service to burst only those when you save something on your backend.\n- Supports CloudFront invalidations.\n- Supports Akamai EdgeCacheTags invalidations.\n- Allow override of Services and easy implementation to support new CDN Services.\n- [Spatie's Laravel Response Cache](#laravel-response-cache-integration) granular invalidations.\n\n## Installation\n\nInstall the package via composer:\n\n```bash\ncomposer require area17/edge-flush\n```\n\nPublish the config file with:\n\n```bash\nphp artisan vendor:publish --provider=\"A17\\EdgeFlush\\ServiceProvider\"\n```\n\nAnd run the migrations:\n\n```bash\nphp artisan migrate\n```\n\n## Dependencies\n\nThe supported CDN services have these package dependencies that you need to choose according to your setup:\n\nAkamai: [akamai-open/edgegrid-auth](https://github.com/akamai/AkamaiOPEN-edgegrid-php)\nCloudFront: [aws/aws-sdk-php](https://github.com/aws/aws-sdk-php)\n\n## Usage\n\nDo a full read on the `config/edge-flush.php` there's a lot of configuration items and we tried to document them all.\n\nDefine your CDN service class on `config/edge-flush.php`:\n\n``` php\n'classes' =\u003e [\n    'cdn' =\u003e A17\\EdgeFlush\\Services\\CloudFront\\Service::class,\n    \n    ...\n]\n```\n\nAdd the trait `A17\\EdgeFlush\\Behaviours\\CachedOnCDN` to your models and repositories.\n\nCall `$this-\u003einvalidateCDNCache($model)` every time a model (on your base model or repository save() method). This example takes in consideration [Twill's](https://twill.io/) repositories:\n\n``` php\npublic function afterSave($object, $fields)\n{\n    $this-\u003einvalidateCDNCache($object);\n\n    parent::afterSave($object, $fields);\n}\n```\n\nCall `$this-\u003ecacheModelOnCDN($model)` method on model's `getAttribute()`:\n\n``` php\npublic function getAttribute($key)\n{\n    $this-\u003ecacheModelOnCDN($this);\n\n    return parent::getAttribute($key);\n}\n```\n\nAdd the Middlware to the `Kernel.php` file:\n\n```\nprotected $middleware = [\n    \\A17\\EdgeFlush\\Middleware::class,\n    ...\n];\n```\n\nCache-Control max-age and s-maxage is set automatically, but if you need to change it depending on the current request you can use the following method:\n\n``` php\nCacheControl::setMaxAge(5000); // in seconds\n\nCacheControl::setMaxAge('1 month'); // as a DateTime string period\n\nCacheControl::setSMaxAge('2 weeks');\n```\n\nIf you want to invalidate your paths in batches, add a scheduler setting the desired frequency for this to happen:\n\n``` php\nprotected function schedule(Schedule $schedule)\n{\n    $schedule-\u003ejob(new PurgeTags())-\u003eeveryMinute();\n}\n```\n\nYou need to enable the package and the warmer on your `.env` file\n\n``` sh\nEDGE_FLUSH_ENABLED=true\nEDGE_FLUSH_WARMER_ENABLED=true\n```\n\n## CDN third-party service configuration\n\nPlease check the respective environment variables needed for supported services to work:\n\n- [Akamai](https://github.com/area17/edge-flush/blob/unstable/config/edge-flush.php#L188)\n- [CloudFront](https://github.com/area17/edge-flush/blob/unstable/config/edge-flush.php#L195)\n\n## Rewarming cache\n\nPurged cache pages can load slowly for the next users or even Google Bot, if you want to prevent this you can enable (on config) the cache warmer and add the job to the schedule:\n\n``` php\nprotected function schedule(Schedule $schedule)\n{\n    $schedule-\u003ejob(new WarmCache())-\u003eeveryMinute();\n}\n```\n\nNote that the most hit (or frequently updated) pages will be warmed first.\n\n## Akamai Edge Cache Tags\n\nAkamai has a 128 bytes limit for the tag list, so if one page is impacted by lots of models, we would have no other way than busting the whole cache every time. This package creates a single Edge Cache Tag that relates to all models touched when the page was rendered, and adds it yo the response header:\n\n```\nedge-cache-tag: app-production-7e0ae085d699003a64e5fa7b75daae3d78ace842\n```\n\n## Invalidating the full cache from the command line\n\nIn case you need to invalidate the whole CDN cache locally or on a deployment routing, you can:\n\n```\nphp artisan edge-flush:invalidate-all\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](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n-   [AREA 17](https://github.com/area17)\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%2Farea17%2Fedge-flush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farea17%2Fedge-flush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farea17%2Fedge-flush/lists"}