{"id":17226796,"url":"https://github.com/dantleech/sf-http-cache-tagging","last_synced_at":"2026-03-07T15:35:02.979Z","repository":{"id":56962277,"uuid":"54131442","full_name":"dantleech/sf-http-cache-tagging","owner":"dantleech","description":"Middleware for tag invalidation with the Symfony HTTP cache.","archived":false,"fork":false,"pushed_at":"2016-04-08T12:37:36.000Z","size":29,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-11T07:05:55.089Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dantleech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-17T15:54:19.000Z","updated_at":"2018-08-09T17:33:33.000Z","dependencies_parsed_at":"2022-08-21T09:50:14.110Z","dependency_job_id":null,"html_url":"https://github.com/dantleech/sf-http-cache-tagging","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dantleech/sf-http-cache-tagging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fsf-http-cache-tagging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fsf-http-cache-tagging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fsf-http-cache-tagging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fsf-http-cache-tagging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dantleech","download_url":"https://codeload.github.com/dantleech/sf-http-cache-tagging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fsf-http-cache-tagging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30219551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T14:02:48.375Z","status":"ssl_error","status_checked_at":"2026-03-07T14:02:43.192Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-10-15T04:17:16.129Z","updated_at":"2026-03-07T15:35:02.963Z","avatar_url":"https://github.com/dantleech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Symfony HTTP Cache Tagging Middleware\n=====================================\n\n[![Build Status](https://travis-ci.org/dantleech/sf-http-cache-tagging.svg?branch=master)](https://travis-ci.org/dantleech/sf-http-cache-tagging)\n[![StyleCI](https://styleci.io/repos/54131442/shield)](https://styleci.io/repos/54131442)\n\nIntroduction\n------------\n\nThis package provides a middleware which allows you to add \"tagging\"\ncapabilties to the [Symfony HTTPCache](http://symfony.com/doc/current/book/http_cache.html).\n\nWhat this means is that you can associate responses with tags, which can later\nbe invalidated. What THIS means is that you can cache your responses\nindefinitely and invalidate them only when the content on the page changes.\n\nFeatures\n--------\n\n- Middleware to add tagging capability to the Symfony HTTP Cache.\n- Configurable and extensible tag storage.\n- Local and remote tag invalidation.\n- Configurable HTTP headers.\n- Configurable tag encoding.\n\nQuick Start\n-----------\n\n### Installation\n\nRequire the library with composer:\n\n    $ composer require dtl/http-cache-tagging\n\nYou will need a storage strategy, it is easiest to use the ``DoctrineCache``\nstrategy, and for this you will need the ``doctrine/cache`` package:\n\n    $ composer require doctrine/cache\n\n### Wrapping the kernel\n\n```php\nuse Doctrine\\Common\\Cache\\PhpFileCache;\nuse Symfony\\Component\\HttpKernel\\HttpCache\\Store;\nuse Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache;\nuse DTL\\Symfony\\HttpCacheTagging\\Storage\\DoctrineCache;\nuse DTL\\Symfony\\HttpCacheTagging\\Manager\\TagManager;\nuse DTL\\Symfony\\HttpCacheTagging\\TaggingKernel;\n\n// your main application\n$app = new TestKernel();\n\n// the standard Symfony HTTP cache\n$store = new Store('/path/to/keep/cache');\n$httpCache = new HttpCache($app, $store);\n\n// our tag storage strategy\n$tagStorage = new DoctrineCache(new PhpFileCache('/path/to/keep/tags'));\n$tagManager = new TagManager($tagStorage, $store);\n\n// now you can procss the request\n$app = new TaggingKernel($httpCache, $tagManager);\n$app-\u003ehandle(Request::create());\n```\n\n### Tagging your response\n\nTo tag the response just add the tags to the configured tag header\n(``X-Cache-Tags`` by default).\n\n```php\nclass MyController\n{\n    // ..\n    public function someAction(Request $request)\n    {\n\n        $id = 1;\n        $entity = $this-\u003eentitymanager-\u003efind($id);\n        $tag = get_class($entity) . $id;\n\n        $response = Response::create($entity-\u003egetHelloWorld());\n        $response-\u003eheaders-\u003eset('X-Cache-Tags', json_encode([ $tag ]));\n\n        return $response;\n    }\n}\n```\n\nNote that above we used JSON encode to convert the tags to a string. A JSON\nencoded string is expected by default, however you may also choose to use\n``comma-seperated`` value strategy or an encoding system of your choice by\nsepecifying a callback in the ``tag_encoding`` option.\n\n### Invalidating cache entries with tags\n\nInvalidation can be done in three different ways:\n\n- Direct invalidation.\n- Request invalidation.\n- Response invalidation.\n\n#### Direct invalidation\n\nIs where you purge the cache directly from your application, for this you will\nneed to inject the ``TagManager`` which you instantiated into your Application\nkernel.\n\n\n#### Request invalidation\n\nIs where you send separate HTTP request to the caching server or servers. By\ndefault this should be a ``POST`` request with the tags encoded in the\n``X-Cache-Invalidate-Tags`` header.\n\nNote that only request invalidation can be used when you have multiple\nservers.\n\n#### Response invalidation\n\nIs where you set the invalidation headers in the HTTP response.\nThis has the same advantage as direct invalidation, but avoids having to\ninject the tag manager as a service. The ``X-Cache-Invalidate-Tags`` header\nis expected by default.\n\nThe response method is probably the most simple:\n\n```php\nclass MyController\n{\n    // ...\n\n    public function editAction(Request $request)\n    {\n        $id = 1;\n        $entity = $this-\u003eentitymanager-\u003efind($id);\n        $tag = get_class($entity) . $id;\n\n        // update the entity\n\n        $response = // get your response\n        $response-\u003eheaders-\u003eset('X-Cache-Invalidate-Tags', json_encode([ $tag ]));\n\n        return $response;\n    }\n}\n```\n\nHere we are editing an object which represents a page on your website, we set\nthe response header, after the response has been sent any cache entries which\nhave the entities tag will be removed.\n\nYou will also need to update the kernel wrapping to:\n```php\n$kernel = new TaggingKernel($httpCache, $tagManager, array('invalidate_from_response' =\u003e true));\n```\n\n### Configuration\n\n- **purge_method**: Purge method to use when invalidating remotely, note that\n  the Symfony HTTP cache does not support the ``PURGE`` method.\n- **header_tags**: Header to use when tagging the response, ``X-Cache-Tags``\n  by default.\n- **header_invalidate_tags**: Header to use for invalidating tags in either\n  request (remote) or response (local). Default is\n  ``X-Cache-Invalidate-Tags``.\n- **tag_encoding**: How the tags should be decoded by the middleware, can be\n  ``json`` (default), ``comma-separate`` or a PHP callable which will receive\n  the raw tag string and return an array.\n- **ips**: List of IP addresses which may remotely invalidate the cache.\n\nLicense\n-------\n\nThis library is released under the MIT license. See the included\n[LICENSE](LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Fsf-http-cache-tagging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdantleech%2Fsf-http-cache-tagging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Fsf-http-cache-tagging/lists"}