{"id":16184321,"url":"https://github.com/mattmezza/cacheasy","last_synced_at":"2025-07-05T08:04:33.115Z","repository":{"id":62525328,"uuid":"127317694","full_name":"mattmezza/cacheasy","owner":"mattmezza","description":"I hate slow APIs, I cache things on disk.","archived":false,"fork":false,"pushed_at":"2018-04-03T15:33:33.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T12:50:16.467Z","etag":null,"topics":["api","cache","caching","caching-library","disk","slow"],"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/mattmezza.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":"2018-03-29T16:23:29.000Z","updated_at":"2022-02-19T11:56:26.000Z","dependencies_parsed_at":"2022-11-02T15:31:02.291Z","dependency_job_id":null,"html_url":"https://github.com/mattmezza/cacheasy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mattmezza/cacheasy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fcacheasy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fcacheasy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fcacheasy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fcacheasy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattmezza","download_url":"https://codeload.github.com/mattmezza/cacheasy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fcacheasy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263707030,"owners_count":23499075,"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":["api","cache","caching","caching-library","disk","slow"],"created_at":"2024-10-10T07:09:50.527Z","updated_at":"2025-07-05T08:04:33.090Z","avatar_url":"https://github.com/mattmezza.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"cacheasy\n=====\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mattmezza/cacheasy/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mattmezza/cacheasy/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/mattmezza/cacheasy/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mattmezza/cacheasy/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/mattmezza/cacheasy/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mattmezza/cacheasy/build-status/master) \n\n\u003e I hate slow APIs, I cache things on disk.\n\n# Install\n\n`composer require mattmezza/cacheasy`\n# Usage\n\nWith string responses:\n\n```php\n$providerStrAPI = new class implements Cacheasy\\StringProvider {\n    public function get() : string\n    {\n        return (new SlowAPIsClient())-\u003eslowAPI();\n    }\n};\n// ./cache is the cache path, 86400 is the time to live\n$cache = new Cache(\"./cache\", 86400);\n// if slowAPI is not cached let's get the data and cache them\n$result = $cache-\u003egetString(\"slowAPI\", $providerStrAPI); # this is slow :(\n$result2 = $cache-\u003egetString(\"slowAPI\", $providerStrAPI); # this is blazing fast :)\necho $result2;\n```\n\nWith JSON responses:\n\n```php\n$providerJsonAPI = new class implements Cacheasy\\JsonProvider {\n    public function get() : array\n    {\n        return (new SlowAPIsClient())-\u003eslowAPI();\n    }\n};\n// ./cache is the cache path, 86400 is the time to live\n$cache = new Cache(\"./cache\", 86400);\n// if slowAPI is not cached let's get the data and cache them\n$result = $cache-\u003egetJson(\"slowjsonAPI\", $providerJsonAPI); # this is slow :(\n$result2 = $cache-\u003egetJson(\"slowjsonAPI\", $providerJsonAPI); # this is blazing fast :)\necho $result2[\"property\"];\n```\n\n# API\n\n- `cacheString($key, $string) : string`: caches a string with key\n- `cacheJson($key, $array) : array`: caches an array to json with key\n- `hitString($key) : string`: tries to resume from cache a string with key\n- `hitJson($key) : array`: tries to resume from cache a json with key\n- `isCached($key) : bool`: checks if key is cached on disk and if it is not expired\n- `getJson($key, $provider = null, bool $forceFresh = false) : array`: returns `hitJson(...)` if key is cached, calls provider otherwise. Throws exception if $provider is null and $key is not cached. If $forceFresh is set to `true` skips isCached check and calls the provider (ultimately caching the data).\n- `getString($key, $provider = null, bool $forceFresh = false) : string`: returns `hitString(...)` if key is cached, calls provider otherwise. Throws exception if $provider is null and $key is not cached. If $forceFresh is set to `true` skips isCached check and calls the provider (ultimately caching the data).\n- `invalidate($key) : void`: deletes the cached resource\n- `invalidateAll() : void`: deletes all the cached resources\n\n## Exceptions\n\n`MissingProviderException`: when `get..(...)` is called for a non cached resource and no provider is passed, or when, even if the resource is cached, the method is invoked with null provider and with `true` force fresh values.\n`NotCachedException`: when you wanna hit the cache but the resource is not cached yet.\n\n# Development\n\n- `git clone https://github.com/mattmezza/cacheasy.git`\n- `cd cacheasy`\n- `composer test`\n\n##### Matteo Merola \u003cmattmezza@gmail.com\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmezza%2Fcacheasy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattmezza%2Fcacheasy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmezza%2Fcacheasy/lists"}