{"id":15162456,"url":"https://github.com/phpsocialnetwork/phpfastcache-bundle","last_synced_at":"2025-09-30T16:31:26.441Z","repository":{"id":57040378,"uuid":"58038227","full_name":"PHPSocialNetwork/phpfastcache-bundle","owner":"PHPSocialNetwork","description":"The symfony 3/Flex bundle for PhpFastCache integrating a phpfastcache service, a twig cache tag and a powerfull cache profiler integrated to the symfony profile","archived":true,"fork":false,"pushed_at":"2018-06-03T14:11:53.000Z","size":383,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-17T14:39:28.142Z","etag":null,"topics":["cacheable-responses","flex-bundle","phpfastcache-bundle","phpfastcache-service","symfony-bundle","symfony-cache"],"latest_commit_sha":null,"homepage":"https://www.phpfastcache.com/","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/PHPSocialNetwork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-04T09:05:52.000Z","updated_at":"2024-06-23T03:16:35.000Z","dependencies_parsed_at":"2022-08-24T00:50:55.592Z","dependency_job_id":null,"html_url":"https://github.com/PHPSocialNetwork/phpfastcache-bundle","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPSocialNetwork%2Fphpfastcache-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPSocialNetwork%2Fphpfastcache-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPSocialNetwork%2Fphpfastcache-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPSocialNetwork%2Fphpfastcache-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PHPSocialNetwork","download_url":"https://codeload.github.com/PHPSocialNetwork/phpfastcache-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234753638,"owners_count":18881428,"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":["cacheable-responses","flex-bundle","phpfastcache-bundle","phpfastcache-service","symfony-bundle","symfony-cache"],"created_at":"2024-09-27T01:43:38.034Z","updated_at":"2025-09-30T16:31:25.825Z","avatar_url":"https://github.com/PHPSocialNetwork.png","language":"PHP","readme":"[![Code Climate](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache-bundle/badges/gpa.svg)](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache-bundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache-bundle/?branch=master) [![Build Status](https://travis-ci.org/PHPSocialNetwork/phpfastcache-bundle.svg?branch=master)](https://travis-ci.org/PHPSocialNetwork/phpfastcache-bundle) [![Latest Stable Version](http://img.shields.io/packagist/v/phpfastcache/phpfastcache-bundle.svg)](https://packagist.org/packages/phpfastcache/phpfastcache-bundle) [![Total Downloads](http://img.shields.io/packagist/dt/phpfastcache/phpfastcache-bundle.svg)](https://packagist.org/packages/phpfastcache/phpfastcache-bundle) [![License](https://img.shields.io/packagist/l/phpfastcache/phpfastcache-bundle.svg)](https://packagist.org/packages/phpfastcache/phpfastcache-bundle)\n# Symfony Flex PhpFastCache Bundle\n\n#### :warning: Please note that the V3 is a major (BC breaking) update of the PhpFastCache Bundle !\n\u003e As of the V3 the bundle is **absolutely** not compatible with previous versions.\\\nTo ensure you the smoothest migration possible, please check the migration guide in the Resources/Docs directory.\\\nOne of the biggest change is the Phpfastcache's dependency which is not set to the v7 which it not backward compatible at all.\n\n#### :thumbsup: Step 1: Include phpFastCache Bundle in your project with composer:\n\n```bash\ncomposer require phpfastcache/phpfastcache-bundle\n```\n\n#### :construction: Step 2: Setup your `config/packages/phpfastcache.yaml` to configure your cache(s) instance(s)\n\n```yml\n# PhpFastCache configuration\nphpfastcache:\n    twig_driver: \"filecache\" # This option must be a valid declared driver, in our example: \"filecache\"\n    twig_block_debug: false # This option will wrap CACHE/ENDCACHE blocks with block debug as HTML comment\n    drivers:\n        filecache:\n            type: Files\n            parameters:\n                path: \"%kernel.cache_dir%/phpfastcache/\"\n```\n* This step can be skipped using [Symfony recipes](https://symfony.com/doc/current/setup/flex.html).\n\n#### :rocket: Step 3: Accelerate your app by making use of PhpFastCache service\n\nCaching data in your controller:\n```php\npublic function indexAction(Request $request, Phpfastcache $phpfastcache)\n{\n    $cache = $phpfastcache-\u003eget('filecache');\n    $item = $cache-\u003egetItem('myAppData');\n    \n    if (!$item-\u003eisHit() || $item-\u003eget() === null) {\n        $item-\u003eset('Wy app has now superpowers !!')-\u003eexpiresAfter(3600);//1 hour\n        $cache-\u003esave($item);\n    } \n     \n    // replace this example code with whatever you need\n    return $this-\u003erender('default/index.html.twig', [\n        'myAppData' =\u003e $item-\u003eget(),\n        'base_dir' =\u003e realpath($this-\u003egetParameter('kernel.root_dir').'/..'),\n    ]);\n}\n```\nOr in your template:\n```twig\n\u003cdiv\u003e\n    {#\n     * 'myrandom6' Is your cache key identifier, must be unique\n     * 300 Is the time to live (TTL) before the cache expires and get regenerated\n    #}\n    {% cache 'myrandom6' 300 %}\n        \u003ctextarea\u003e\n            \u003c!-- Some heavy stuff like Doctrine Lazy Entities --\u003e\n            {% for i in 1..1000 %}{{ random() }}{% endfor %}\n        \u003c/textarea\u003e\n    {% endcache %}\n\u003c/div\u003e\n```\n\n#### :computer: CLI command interactions\nAs of the V3, some command-line tools were introduced, mostly for CRUD-like operations.\n\n##### GET operation\n```bash\nphp bin/console phpfastcache:get filecache cacheKey\n```\nThis will display the content of a cache item if it eventually exists.\n\n\n##### SET operation\n```bash\nphp bin/console phpfastcache:get filecache cacheKey '{\"a\": 14}' 300 -a 1\n```\nThis will set the content of a cache item.\\\nThe TTL (300), in seconds, is optional and take the default value filled in your configuration file.\\\nThe `auto-type-cast` option  _\"-a\"_ (enabled by default) will let allows you to automatically type cast your variable:\n- `false` and `true` will be respectively converted to _boolean_.\n- `1337` and `1337.666` will be respectively be converted to _integer_ or _float_.\n- `null` will be converted to _null_.\n- `{\"a\": 14}` will be converted to an associative _array_ using a JSON detection\n- `a regular string` will remains unchanged and stays a string\n\nYou can obviously disable this behavior by turning off the `auto-type-cast` option: `-a 0`\n\n##### DELETE operation\n```bash\nphp bin/console phpfastcache:del filecache cacheKey\n```\nThis will delete the specified cache item. \n\n##### CLEAR operation\n```bash\nphp bin/console phpfastcache:clear filecache\n# OR to clear every caches:\nphp bin/console phpfastcache:clear\n```\nThis will clear a single cache instance if specified or all the configured cache instances otherwise.\n\n#### :bulb: Introducing Cacheable Responses (V3 only)\nAs of the V3 there's a new, easier and cleaner way to setup HTTP cache to decrease your server bandwidth along with your CPU load: Cacheable Responses.\nAnd it's pretty easy to implement:\n```php\n    /**\n     * @Route(\"/cached\", name=\"cached\")\n     */\n    public function cachedAction(Phpfastcache $phpfastcache, Request $request): Response\n    {\n        return (new CacheableResponse($phpfastcache-\u003eget('filecache'), $request))-\u003egetResponse('cache_key', 3600, function () {\n            return new Response('Random bytes: ' . \\random_bytes(255));\n        });\n    }\n``` \n`CacheableResponse` is provided by `\\Phpfastcache\\Bundle\\Response\\CacheableResponse`.\nThis class will handle responses headers (cache-control, etag, etc...) and http status (304 Not modified).\n\n#### :boom: phpFastCache Bundle support\nFound an issue or had an idea ? Come here [here](https://github.com/PHPSocialNetwork/phpfastcache-bundle/issues) and let us know !\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpsocialnetwork%2Fphpfastcache-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpsocialnetwork%2Fphpfastcache-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpsocialnetwork%2Fphpfastcache-bundle/lists"}