{"id":17236314,"url":"https://github.com/there4/slim-stash-middleware","last_synced_at":"2025-04-14T02:14:33.325Z","repository":{"id":22217849,"uuid":"25550624","full_name":"there4/slim-stash-middleware","owner":"there4","description":"Slim Stash Cache Middleware","archived":false,"fork":false,"pushed_at":"2014-11-22T23:41:52.000Z","size":200,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-14T02:14:24.767Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/there4.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":"2014-10-21T23:06:37.000Z","updated_at":"2016-12-17T14:01:45.000Z","dependencies_parsed_at":"2022-08-20T23:20:25.539Z","dependency_job_id":null,"html_url":"https://github.com/there4/slim-stash-middleware","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-stash-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-stash-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-stash-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-stash-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/there4","download_url":"https://codeload.github.com/there4/slim-stash-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809058,"owners_count":21164896,"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-10-15T05:35:53.413Z","updated_at":"2025-04-14T02:14:33.302Z","avatar_url":"https://github.com/there4.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Slim Stash Cache Middleware [![Build Status](https://travis-ci.org/there4/slim-stash-middleware.svg)](https://travis-ci.org/there4/slim-stash-middleware)\n================================================================================\n\u003e Caching middleware layer for Slim using Stash\n\n## About\n\nA simple middleware layer for Slim that provides a caching mechanism for\nendpoints.\n\n## Example Setup\n\nHere is an example of the middleware setup. It's using a config setting to\nenable the cache.\n\n```php\n\u003c?php\n// Stash Page Cache Middleware\n// -----------------------------------------------------------------------------\n// A generalized way of caching the output of an endpoint\n$app-\u003econtainer-\u003esingleton('stash', function () use ($app) {\n    if (!is_dir($app-\u003econfig('caches.path'))) {\n        mkdir($app-\u003econfig('caches.path'), 0777, true);\n    }\n    $stashFileSystem = new \\Stash\\Driver\\FileSystem(array(\n        'path' =\u003e $app-\u003econfig('caches.path')\n    ));\n    return new \\Stash\\Pool($stashFileSystem);\n});\n\nif ($app-\u003econfig('enable_cache')) {\n    $app-\u003eadd(new \\There4\\Slim\\Middleware\\StashCache($app-\u003estash));\n}\n```\n\nAnd an endpoint that uses the cache:\n\n```php\n\u003c?php\n// Root of the site\n// -----------------------------------------------------------------------------\n// Simple index page - no data\n$app-\u003eget('/', function () use ($app) {\n    $app-\u003eresponse-\u003eallowCache = true;\n    $app-\u003eresponse-\u003ecacheExpiration = 3600;\n    $app-\u003erender('index.html');\n});\n\n// User Profile Page\n// -----------------------------------------------------------------------------\n// This would need to be coupled with a cache invalidation on a user change\n$app-\u003eget('/profile', function () use ($app) {\n    $user = $app-\u003ecurrentUser;\n    $app-\u003eresponse-\u003eallowCache = true;\n    $app-\u003eresponse-\u003ecacheExpiration = 3600;\n    $app-\u003eresponse-\u003esignature = 'userProfile' . $user-\u003eid;\n    $app-\u003erender('index.html');\n});\n```\n\n## Quick API Reference\n\n* __$app-\u003eresponse-\u003eallowCache__ `bool` enable caching\n* __$app-\u003eresponse-\u003ecacheExpiration__ `int` seconds to hold data in cache;\n* __$app-\u003eresponse-\u003esignature__ `mixed` leave unset for automatic url based. String for simple signature. Callback function will be executed. Array in `call_user_func` format is acceptable as well.\n\n\n## TODO\n\n* Cache warming script\n* Tests\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthere4%2Fslim-stash-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthere4%2Fslim-stash-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthere4%2Fslim-stash-middleware/lists"}