{"id":14966391,"url":"https://github.com/yiisoft/cache-file","last_synced_at":"2025-10-19T09:31:17.711Z","repository":{"uuid":"184578437","full_name":"yiisoft/cache-file","owner":"yiisoft","description":"Yii Cache Library - File Handler","archived":false,"fork":false,"pushed_at":"2024-04-04T02:20:43.000Z","size":152,"stargazers_count":12,"open_issues_count":2,"forks_count":12,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-04-14T02:32:29.743Z","etag":null,"topics":["cache","cache-storage","file","hacktoberfest","psr-16","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","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/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2019-05-02T12:38:46.000Z","updated_at":"2024-04-15T09:05:29.852Z","dependencies_parsed_at":"2024-03-04T12:07:54.486Z","dependency_job_id":"1048ec26-e1e2-41b2-8b77-a74244792f1e","html_url":"https://github.com/yiisoft/cache-file","commit_stats":{"total_commits":110,"total_committers":19,"mean_commits":"5.7894736842105265","dds":0.6545454545454545,"last_synced_commit":"5839332fe7748a7f59cd16fea1dddda34ff5e0c1"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/cache-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":199584513,"owners_count":13621179,"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":["cache","cache-storage","file","hacktoberfest","psr-16","yii3"],"created_at":"2024-09-24T13:36:18.942Z","updated_at":"2025-10-19T09:31:17.705Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Cache Library - File Handler\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/cache-file/v)](https://packagist.org/packages/yiisoft/cache-file)\n[![Total Downloads](https://poser.pugx.org/yiisoft/cache-file/downloads)](https://packagist.org/packages/yiisoft/cache-file)\n[![Build status](https://github.com/yiisoft/cache-file/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/cache-file/actions/workflows/build.yml)\n[![Code Coverage](https://codecov.io/gh/yiisoft/cache-file/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/cache-file)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fcache-file%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/cache-file/master)\n[![static analysis](https://github.com/yiisoft/cache-file/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/cache-file/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/cache-file/coverage.svg)](https://shepherd.dev/github/yiisoft/cache-file)\n\nThis package implements file-based [PSR-16](https://www.php-fig.org/psr/psr-16/) cache.\n\n## Requirements\n\n- PHP 8.1 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/cache-file\n```\n\n## Configuration\n\nWhen creating an instance of `\\Yiisoft\\Cache\\File\\FileCache`, you must specify\nthe path to the base directory in which the cache files will be stored:\n\n```php\n$cache = new \\Yiisoft\\Cache\\File\\FileCache('/path/to/directory');\n```\n\nChange the permission to be set for newly created directories:\n\n```php\n$cache = new \\Yiisoft\\Cache\\File\\FileCache('/path/to/directory', 0777); // default is 0775\n```\n\nThis value will be used by PHP `chmod()` function. No umask will be applied. Defaults to 0775,\nmeaning the directory is read-writable by an owner and group, but read-only for other users.\n\nChange the suffix of the cache files:\n\n```php\n$cache = $cache-\u003ewithFileSuffix('.txt'); // default is '.bin'\n```\n\nChange the permission to be set for newly created cache files:\n\n```php\n$cache = $cache-\u003ewithFileMode(0644); // default is null\n```\n\nThis value will be used by PHP `chmod()` function. No umask will be applied.\nIf not set, the permission will be determined by the current environment.\n\nChange the level of sub-directories to store cache files:\n\n```php\n$cache = $cache-\u003ewithDirectoryLevel(3); // default is 1\n```\n\nIf the system has huge number of cache files (e.g. one million), you may use a bigger\nvalue (usually no bigger than 3). Using sub-directories is mainly to ensure the file\nsystem is not over burdened with a single directory having too many files.\n\nChange the probability of performing garbage collection when storing a piece of data in the cache:\n\n```php\n$cache = $cache-\u003ewithGcProbability(1000); // default is 10\n```\n\nThe probability (parts per million) that garbage collection (GC) should be performed when\nstoring a piece of data in the cache. Defaults to 10, meaning 0.001% chance. This number\nshould be between 0 and 1000000. A value 0 means no GC will be performed at all.\n\n## General usage\n\nThe package does not contain any additional functionality for interacting with the cache,\nexcept those defined in the [PSR-16](https://www.php-fig.org/psr/psr-16/) interface.\n\n```php\n$cache = new \\Yiisoft\\Cache\\File\\FileCache('/path/to/directory');\n$parameters = ['user_id' =\u003e 42];\n$key = 'demo';\n\n// try retrieving $data from cache\n$data = $cache-\u003eget($key);\n\nif ($data === null) {\n    // $data is not found in cache, calculate it from scratch\n    $data = calculateData($parameters);\n    \n    // store $data in cache for an hour so that it can be retrieved next time\n    $cache-\u003eset($key, $data, 3600);\n}\n\n// $data is available here\n```\n\nIn order to delete value you can use:\n\n```php\n$cache-\u003edelete($key);\n// Or all cache\n$cache-\u003eclear();\n```\n\nTo work with values in a more efficient manner, batch operations should be used:\n\n- `getMultiple()`\n- `setMultiple()`\n- `deleteMultiple()`\n\nThis package can be used as a cache handler for the [Yii Caching Library](https://github.com/yiisoft/cache).\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Cache Library - File Handler is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fcache-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fcache-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fcache-file/lists"}