{"id":22324992,"url":"https://github.com/o2ps/cachefactory","last_synced_at":"2025-07-29T16:32:40.236Z","repository":{"id":34249173,"uuid":"38132549","full_name":"o2ps/CacheFactory","owner":"o2ps","description":"Simple cache factory extension for Nette.","archived":false,"fork":false,"pushed_at":"2018-07-26T09:17:02.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-02T11:53:49.705Z","etag":null,"topics":["caching","nette","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/o2ps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-26T20:38:09.000Z","updated_at":"2023-01-07T12:47:45.000Z","dependencies_parsed_at":"2022-08-03T20:00:32.878Z","dependency_job_id":null,"html_url":"https://github.com/o2ps/CacheFactory","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2ps%2FCacheFactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2ps%2FCacheFactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2ps%2FCacheFactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2ps%2FCacheFactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/o2ps","download_url":"https://codeload.github.com/o2ps/CacheFactory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228030048,"owners_count":17858432,"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":["caching","nette","php"],"created_at":"2024-12-04T02:09:42.806Z","updated_at":"2024-12-04T02:09:43.464Z","avatar_url":"https://github.com/o2ps.png","language":"PHP","readme":"# Oops/CacheFactory\n\n:warning: **THIS PACKAGE IS NO LONGER MAINTAINED.** You can use [contributte/cache](https://github.com/contributte/cache) instead.\n\nCaching is a very common task in web development. The current practice of creating `Cache` instances in Nette is to enumerate `IStorage` as a dependency and create the `Cache` by hand, as seen [in the docs](http://doc.nette.org/en/2.3/caching#toc-storage-service). This, however, makes unit testing classes that depend on cache a pain in the you-know-what. You either need to mock the storage and go through `Cache` code to find what methods are called upon the storage, or use some [autoloading magic](http://docs.mockery.io/en/latest/cookbook/mocking_hard_dependencies.html). I don't think either way is a good one to go. I've found myself writing a simple factory like the one in this package on every project, so I made an extension out of it.\n\n\n## Installation and requirements\n\n```bash\n$ composer require oops/cache-factory\n```\n\nOops/CacheFactory requires PHP \u003e= 5.6.\n\n\n## Usage\n\nRegister the extension in your config:\n\n```yaml\nextensions:\n\tcacheFactory: Oops\\CacheFactory\\DI\\CacheFactoryExtension\n```\n\nAnd replace all occurrences of direct `Cache` instantiation with call to the factory, so that this:\n\n```php\nclass CachedFoo\n{\n\tprivate $cache;\n\n\tpublic function __construct(Nette\\Caching\\IStorage $cacheStorage)\n\t{\n\t\t$this-\u003ecache = new Nette\\Caching\\Cache($cacheStorage, 'namespace');\n\t}\n}\n```\n\nbecomes this:\n\n```php\nclass CachedFoo\n{\n\tprivate $cache;\n\n\tpublic function __construct(Oops\\CacheFactory\\Caching\\CacheFactory $cacheFactory)\n\t{\n\t\t$this-\u003ecache = $cacheFactory-\u003ecreate('namespace');\n\t}\n}\n```\n\nThe factory automatically uses the storage registered in the config. To provide backwards compatibility, you can also pass to the factory an arbitrary storage, should you need it:\n\n```php\n$cacheFactory-\u003ecreate('namespace', new Nette\\Caching\\Storages\\DevNullStorage());\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo2ps%2Fcachefactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fo2ps%2Fcachefactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo2ps%2Fcachefactory/lists"}