{"id":21616041,"url":"https://github.com/ecomdev/cache-key","last_synced_at":"2025-07-06T21:34:01.766Z","repository":{"id":56974721,"uuid":"58111578","full_name":"EcomDev/cache-key","owner":"EcomDev","description":"Cache key generator library, useful for not worrying about your cache key structure at all, library does all the magic for you","archived":false,"fork":false,"pushed_at":"2016-05-20T18:45:03.000Z","size":29,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-11T19:34:50.571Z","etag":null,"topics":[],"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/EcomDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-05-05T07:08:14.000Z","updated_at":"2025-05-10T00:05:38.000Z","dependencies_parsed_at":"2022-08-21T11:50:47.846Z","dependency_job_id":null,"html_url":"https://github.com/EcomDev/cache-key","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/EcomDev/cache-key","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fcache-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fcache-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fcache-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fcache-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EcomDev","download_url":"https://codeload.github.com/EcomDev/cache-key/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fcache-key/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263975750,"owners_count":23538387,"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-11-24T22:13:25.685Z","updated_at":"2025-07-06T21:34:01.743Z","avatar_url":"https://github.com/EcomDev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cache Key [![Build Status](https://travis-ci.org/EcomDev/cache-key.svg)](https://travis-ci.org/EcomDev/cache-key)  [![Coverage Status](https://coveralls.io/repos/github/EcomDev/cache-key/badge.svg?branch=develop)](https://coveralls.io/github/EcomDev/cache-key?branch=develop)\n\nLibrary that allows you to generate cache keys based on various data formats.\n\nMain components:\n* **Key generator** Allows to generate a cache key based on different data input\n* **Key converters** Allows to convert various php data types into key friendly data type\n* **Key normalizer** Normalizes characters in generated string to match particular cache key sanity checks of your own cache adapter.  \n   \n## Installation\n```bash\ncomposer require ecomdev/cache-key\n```\n\n## Usage\n\n### Automatic non alpha-num characters encoding\n```php\nuse EcomDev\\CacheKey\\Normalizer\\EncodeNormalizer;\nuse EcomDev\\CacheKey\\Generator;\n\n$generator = new Generator(new EncodeNormalizer());\n$generator-\u003egenerate('some_bad_#^.;:/\\\\_character'); // Generates \"some_bad_235e2e3b3a2f5c_character\"\n```\n\n### Multiple normalizers\n```php\nuse EcomDev\\CacheKey\\Normalizer\\EncodeNormalizer;\nuse EcomDev\\CacheKey\\Normalizer\\LengthNormalizer;\nuse EcomDev\\CacheKey\\NormalizerChain;\nuse EcomDev\\CacheKey\\Generator;\n\n$normalizer = new NormalizerChain([\n    new EncodeNormalizer(),\n    new LengthNormalizer(16)\n]);\n\n$generator = new Generator($normalizer);\n$generator-\u003egenerate('some_bad_#^.;:/\\\\_character'); // Generates \"some_bad_235e2e3b3a2f5c_character\"\n```\n\n### Using converter for key value map\n```php\nuse EcomDev\\CacheKey\\Normalizer\\EncodeNormalizer;\nuse EcomDev\\CacheKey\\Converter\\KeyValueConverter;\nuse EcomDev\\CacheKey\\Converter\\ScalarConverter;\nuse EcomDev\\CacheKey\\Generator;\n\n$generator = new Generator(\n    new EncodeNormalizer(), \n    new KeyValueConverter(new ScalarConverter())\n);\n\n$generator-\u003egenerate([\n    'some-key' =\u003e 'some-value', \n    'another-key' =\u003e 'another-value'\n]); // Generates \"some-key_some-value_another-key_another-value\"\n```\n\n### Cache Key Info Provider Usage\n\nYour custom cache able model \n```php\nclass YourCustomModel implements EcomDev\\CacheKey\\InfoProviderInterface\n{\n    public function getCacheKeyInfo()\n    {\n        return [\n            'some-key' =\u003e 'some-value', \n            'another-key' =\u003e 'another-value'\n        ];\n    }\n}\n```\n\nUsage in key generation\n\n```php\nuse EcomDev\\CacheKey\\Normalizer\\EncodeNormalizer;\nuse EcomDev\\CacheKey\\Converter\\KeyValueConverter;\nuse EcomDev\\CacheKey\\Converter\\ScalarConverter;\nuse EcomDev\\CacheKey\\Generator;\n\n$object = new YourCustomModel();\n\n$generator = new Generator(\n    new EncodeNormalizer(), \n    new KeyValueConverter(new ScalarConverter())\n);\n\n$generator-\u003egenerate($object); // Generates \"some-key_some-value_another-key_another-value\"\n```\n\n### PSR-6 compatible key generation\n```php\nuse EcomDev\\CacheKey\\Normalizer\\Psr6Normalizer;\nuse EcomDev\\CacheKey\\Generator;\n\n$generator = new Generator(Psr6Normalizer::create());\n$generator-\u003egenerate('give_me-psr-6-compatible_#^.;:/\\\\-key'); // Generates \"give_me-psr-6-compatible_235e.3b3a2f5c-key\"\n```\n\n### Prefixed Key Generation\n```php\nuse EcomDev\\CacheKey\\Normalizer\\Psr6Normalizer;\nuse EcomDev\\CacheKey\\Generator;\n\n$generator = new Generator(Psr6Normalizer::create(), null, 'prefix-');\n$generator-\u003egenerate('some-non-prefixed-key'); // Generates \"prefix-some-non-prefixed-key\"\n```\n\n## Contribution\nMake a pull request based on develop branch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomdev%2Fcache-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomdev%2Fcache-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomdev%2Fcache-key/lists"}