{"id":17226840,"url":"https://github.com/dantleech/tagged-symfony-cache","last_synced_at":"2025-03-25T17:48:29.279Z","repository":{"id":66290761,"uuid":"46937325","full_name":"dantleech/tagged-symfony-cache","owner":"dantleech","description":"Middleware for tag purging for the Symfony HTTP cache","archived":false,"fork":false,"pushed_at":"2015-11-27T10:04:21.000Z","size":12,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T15:44:22.777Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dantleech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-26T16:33:02.000Z","updated_at":"2015-12-15T14:18:09.000Z","dependencies_parsed_at":"2023-02-22T13:00:37.183Z","dependency_job_id":null,"html_url":"https://github.com/dantleech/tagged-symfony-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Ftagged-symfony-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Ftagged-symfony-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Ftagged-symfony-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Ftagged-symfony-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dantleech","download_url":"https://codeload.github.com/dantleech/tagged-symfony-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245515155,"owners_count":20628115,"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":[],"created_at":"2024-10-15T04:17:22.432Z","updated_at":"2025-03-25T17:48:29.257Z","avatar_url":"https://github.com/dantleech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Tagged (Symfony) Http Cache\n===========================\n\nThis is an experimental middleware that wraps the Symfony HTTP cache and\nallows invalidation by tags. This allows you to effectively cache your content\nuntil it is specifically invalidated.\n\nFor example: You have a page which shows content from your database with IDs\n`12` and `6`. When you display the page you send a header in the response with\nthose IDs (the tags). The Middleware will listen for these headers and\nreference them with the cached page.\n\nNow, when you save your content (i.e. the content with IDs `12` or `6`) you\nmust invalidate these tags via. the `TagManager` service in this library, and\nthen the cache will be refreshed only for pages with those tags.\n\nUsage\n-----\n\nThe following assumes you have only one server (and so can access the cache\nfiles directly).\n\nThe first step is to modify you AppKernel so that we can inject the\n`TagManager` later on:\n\n```php\n\u003c?php\n\n// ...\nuse DTL\\TaggedHttpCache\\TagManagerInterface;\nuse DTL\\TaggedHttpCache\\NullTagManager;\n\nclass AppKernel extends Kernel\n{\n    private $tagManager;\n\n    public function __construct($environment, $debug, TagManagerInterface $tagManager = null)\n    {\n        $this-\u003etagManager = $tagManager ?: new NullTagManager();\n        parent::__construct($environment, $debug);\n    }\n\n    public function getTagManager()\n    {\n        return $this-\u003etagManager;\n    }\n\n    protected function buildContainer()\n    {\n        $container = parent::buildContainer();\n        $definition = new Definition('DTL\\TaggedHttpCache\\TagManager');\n        $definition-\u003esetFactory(array(\n            new Reference('kernel'),\n            'getTagManager'\n        ));\n        $container-\u003esetDefinition('tagged_http_cache.tag_manager', $definition);\n\n        return $container;\n    }\n```\n\nNow change you `web/app.php` as follows:\n\n```php\n\u003c?php\n// AppKernel.php\n\n// ...\nuse Symfony\\Component\\HttpKernel\\HttpCache\\Store;\nuse Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache;\nuse DTL\\TaggedHttpCache\\TaggedCache;\nuse DTL\\TaggedHttpCache\\TagManager;\n\n// create the standard Symfony cache store\n$store = new Store(__DIR__ . '/../app/cache/http_cache');\n\n// create the tag manager\n$tagManager = new TagManager($store, __DIR__ . '/../app/cache/http_cache_tags');\n\n// pass the tag manager to the kernel\n$appKernel = new AppKernel('prod', false, $tagManager);\n$appKernel-\u003eloadClassCache();\n\n// instantiate the Symfony HTTP cache\n$kernel = new HttpCache($appKernel, $store);\n\n// wrap the Symfony HTTP cache with the TaggedCache\n$kernel = new TaggedCache($kernel, $tagManager);\n\n// ...\n```\n\nTo use the cache you will need to send the tag headers in the response:\n\n```php\n\nclass MyController\n{\n    public function myAction(Request $request)\n    {\n        $response = // you somehow have the Response object\n        $response-\u003eheaders-\u003eset(TaggedCache::HEADER_TAGS, json_encode(array('one', 'two')));\n        $response-\u003esetPublic();\n\n        return $response;\n    }\n}\n```\n\nNow you will need to invalidate when you update your content, in the first\nstage you hacked the kernel so you should now have the\n`tagged_http_cache.tag_manager` service. You can invalidate certain tags as\nfollows:\n\n```php\n\u003c?php\n\n$container-\u003eget('tagged_http_cache.tag_manager')-\u003einvalidateTags(array('one', 'two'));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Ftagged-symfony-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdantleech%2Ftagged-symfony-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Ftagged-symfony-cache/lists"}