{"id":20463391,"url":"https://github.com/atiksoftware/static-cache","last_synced_at":"2026-05-31T22:31:05.234Z","repository":{"id":62549751,"uuid":"487602995","full_name":"atiksoftware/static-cache","owner":"atiksoftware","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-01T23:29:32.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-01T05:44:16.743Z","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/atiksoftware.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":"2022-05-01T17:45:56.000Z","updated_at":"2022-05-01T21:52:28.000Z","dependencies_parsed_at":"2022-11-03T01:30:32.125Z","dependency_job_id":null,"html_url":"https://github.com/atiksoftware/static-cache","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/atiksoftware/static-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atiksoftware%2Fstatic-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atiksoftware%2Fstatic-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atiksoftware%2Fstatic-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atiksoftware%2Fstatic-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atiksoftware","download_url":"https://codeload.github.com/atiksoftware/static-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atiksoftware%2Fstatic-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33752286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-15T13:10:55.162Z","updated_at":"2026-05-31T22:31:05.217Z","avatar_url":"https://github.com/atiksoftware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Page Cache\n\n\n[![Latest Stable Version][ico-version]][link-packagist]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![License][ico-license]](LICENSE.txt)\n\nThis package allows you to easily cache responses as static files on disk for lightning fast page loads.\n\n\u003e **Note:** This package inspired by [JosephSilber/page-cache](https://github.com/JosephSilber/page-cache)\n\n- [Introduction](#introduction)\n- [Introduction](#introduction)\n- [Installation](#installation)\n  - [Service Provider](#service-provider)\n  - [Middleware](#middleware)\n  - [URL rewriting](#url-rewriting)\n  - [Ignoring the cached files](#ignoring-the-cached-files)\n- [Usage](#usage)\n  - [Using the middleware](#using-the-middleware)\n  - [Clearing the cache](#clearing-the-cache)\n  - [Customizing what to cache](#customizing-what-to-cache)\n- [License](#license)\n\n---\n\n## Introduction\n\nWhile static site builders such as [Jekyll](https://jekyllrb.com/) and [Jigsaw](https://jigsaw.tighten.co/) are extremely popular these days, dynamic PHP sites still offer a lot of value even for a site that is mostly static. A proper PHP site allows you to easily add dynamic functionality wherever needed, and also means that there's no build step involved in pushing updates to the site.\n\nThat said, for truly static pages on a site there really is no reason to have to boot up a full PHP app just to serve a static page. Serving a simple HTML page from disk is infinitely faster and less taxing on the server.\n\nThe solution? Full page caching.\n\nUsing the middleware included in this package, you can selectively cache the response to disk for any given request. Subsequent calls to the same page will be served directly as a static HTML page!\n\n## Installation\n\nInstall the `static-cache` package with composer:\n\n```\n$ composer require atiksoftware/static-cache\n```\n\n### Service Provider\n\n\u003e **Note**: If you're using Laravel 5.5+, the service provider will be registered automatically. You can simply skip this step entirely.\n\nOpen `config/app.php` and add a new item to the `providers` array:\n\n```php\nAtiksoftware\\StaticCache\\LaravelServiceProvider::class,\n```\n\n### Middleware\n\nOpen `app/Http/Kernel.php` and add a new item to the `web` middleware group:\n\n```php\nprotected $middlewareGroups = [\n    'web' =\u003e [\n        \\Atiksoftware\\StaticCache\\Middleware\\CacheResponse::class,\n        /* ... keep the existing middleware here */\n    ],\n];\n```\n\nThe middleware is smart enough to only cache responses with a 200 HTTP status code, and only for GET requests.\n\nIf you want to selectively cache only specific requests to your site, you should instead add a new mapping to the `routeMiddleware` array:\n\n```php\nprotected $routeMiddleware = [\n    'static-cache' =\u003e \\Atiksoftware\\StaticCache\\Middleware\\CacheResponse::class,\n    /* ... keep the existing mappings here */\n];\n```\n\nOnce registered, you can then [use this middleware on individual routes](#using-the-middleware).\n\n### URL rewriting\n\nIn order to serve the static files directly once they've been cached, you need to properly configure your web server to check for those static files.\n\n- **For nginx:**\n\n    Update your `location` block's `try_files` directive to include a check in the `static-cache` directory:\n\n    ```nginxconf\n    location = / {\n        try_files /static-cache/__index.html /index.php?$query_string;\n    }\n\n    location / {\n        try_files $uri $uri/ /static-cache/$uri.html /static-cache/$uri.json /static-cache/$uri.xml /index.php?$query_string;\n    }\n    ```\n\n- **For apache:**\n\n    Open `public/.htaccess` and add the following before the block labeled `Handle Front Controller`:\n\n    ```apacheconf\n    # Serve Cached Page If Available...\n    RewriteCond %{REQUEST_URI} ^/?$\n    RewriteCond %{DOCUMENT_ROOT}/static-cache/__index.html -f\n    RewriteRule .? static-cache/__index.html [L]\n    \n    RewriteCond %{DOCUMENT_ROOT}/static-cache%{REQUEST_URI}.html -f\n    RewriteRule . static-cache%{REQUEST_URI}.html [L]\n    RewriteCond %{DOCUMENT_ROOT}/static-cache%{REQUEST_URI}[%{QUERY_STRING}].html -f\n    RewriteRule . static-cache%{REQUEST_URI}[%{QUERY_STRING}].html [L]\n\n    RewriteCond %{DOCUMENT_ROOT}/static-cache%{REQUEST_URI}.json -f\n    RewriteRule . static-cache%{REQUEST_URI}.json [L]\n    RewriteCond %{DOCUMENT_ROOT}/static-cache%{REQUEST_URI}[%{QUERY_STRING}].json -f\n    RewriteRule . static-cache%{REQUEST_URI}[%{QUERY_STRING}].json [L] \n\n    RewriteCond %{DOCUMENT_ROOT}/static-cache%{REQUEST_URI}.xml -f\n    RewriteRule . static-cache%{REQUEST_URI}.xml [L]\n    RewriteCond %{DOCUMENT_ROOT}/static-cache%{REQUEST_URI}[%{QUERY_STRING}].xml -f\n    RewriteRule . static-cache%{REQUEST_URI}[%{QUERY_STRING}].xml [L]\n    ```\n\n### Ignoring the cached files\n\nTo make sure you don't commit your locally cached files to your git repository, add this line to your `.gitignore` file:\n\n```\n/public/static-cache\n```\n\n## Usage\n\n### Using the middleware\n\n\u003e **Note:** If you've added the middleware to the global `web` group, then all successful GET requests will automatically be cached. No need to put the middleware again directly on the route.\n\u003e\n\u003e If you instead registered it as a route middleware, you should use the middleware on whichever routes you want to be cached.\n\nTo cache the response of a given request, use the `static-cache` middleware:\n\n```php\nRoute::middleware('static-cache')-\u003eget('/haberler', [\\App\\Http\\Controllers\\App\\PostController::class, 'index'])-\u003ename('posts');\nRoute::middleware('static-cache')-\u003eget('/haberler/kategori/{category:slug}', [\\App\\Http\\Controllers\\App\\PostController::class, 'by_category'])-\u003escopeBindings()-\u003ename('posts.by_category');\nRoute::middleware('static-cache')-\u003eget('/haberler/ilce/{district:slug}', [\\App\\Http\\Controllers\\App\\PostController::class, 'by_district'])-\u003escopeBindings()-\u003ename('posts.by_district');\nRoute::middleware('static-cache')-\u003eget('/haberler/yazar/{user:slug}', [\\App\\Http\\Controllers\\App\\PostController::class, 'by_user'])-\u003escopeBindings()-\u003ename('posts.by_user');\nRoute::middleware('static-cache')-\u003eget('/haber/{post:slug}', [\\App\\Http\\Controllers\\App\\PostController::class, 'view'])-\u003escopeBindings()-\u003ename('post');\nRoute::middleware('static-cache')-\u003eget('/haberler/{tag:name}', [\\App\\Http\\Controllers\\App\\PostController::class, 'by_tags'])-\u003ename('posts.by_tags');\n\n```\n\nEvery post will now be cached to a file under the `public/static-cache` directory, closely matching the URL structure of the request. All subsequent  requests for this post will be served directly from disk, never even hitting your app!\n\n### Clearing the cache\n\nSince the responses are cached to disk as static files, any updates to those pages in your app will not be reflected on your site. To update pages on your site, you should clear the cache with the following command:\n\n```\nphp artisan static-cache:clear\n```\n\nAs a rule of thumb, it's good practice to add this to your deployment script. That way, whenever you push an update to your site the page cache will automatically be cleared.\n\nIf you're using [Forge](https://forge.laravel.com)'s Quick Deploy feature, you should add this line to the end of your Deploy Script. This'll ensure that the cache is cleared whenever you push an update to your site.\n\nYou may optionally pass a URL slug to the command, to only delete the cache for a specific page:\n\n```\nphp artisan static-cache:clear posts/first-post\nphp artisan static-cache:clear posts*\nphp artisan static-cache:clear posts/first*\n``` \n \n\n\n### Customizing what to cache\n\nBy default, all GET requests with a 200 HTTP response code are cached. If you want to change that, create your own middleware that extends the package's base middleware, and override the `shouldCache` method with your own logic.\n\n1. Run the `make:middleware` Artisan command to create your middleware file:\n\n    ```\n    php artisan make:middleware CacheResponse\n    ```\n\n2. Replace the contents of the file at `app/Http/Middleware/CacheResponse.php` with this:\n\n    ```php\n    \u003c?php\n\n    namespace App\\Http\\Middleware;\n\n    use Symfony\\Component\\HttpFoundation\\Request;\n    use Symfony\\Component\\HttpFoundation\\Response;\n    use Atiksoftware\\StaticCache\\Middleware\\CacheResponse as BaseCacheResponse;\n\n    class CacheResponse extends BaseCacheResponse\n    {\n        protected function shouldCache(Request $request, Response $response)\n        {\n            // In this example, we don't ever want to cache pages if the\n            // URL contains a query string. So we first check for it,\n            // then defer back up to the parent's default checks.\n            if ($request-\u003egetQueryString()) {\n                return false;\n            }\n\n            return parent::shouldCache($request, $response);\n        }\n    }\n    ```\n\n3. Finally, update the middleware references in your `app/Http/Kernel.php` file, to point to your own middleware.\n\n## License\n\nThe Page Cache package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n[ico-downloads]: https://poser.pugx.org/atiksoftware/static-cache/downloads\n[ico-license]: https://poser.pugx.org/atiksoftware/static-cache/license\n[ico-travis]: https://travis-ci.org/Josephatiksoftware/static-cache.svg\n[ico-version]: https://poser.pugx.org/atiksoftware/static-cache/v/stable\n\n[link-downloads]: https://packagist.org/packages/atiksoftware/static-cache\n[link-packagist]: https://packagist.org/packages/atiksoftware/static-cache\n[link-travis]: https://travis-ci.org/Josephatiksoftware/static-cache\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatiksoftware%2Fstatic-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatiksoftware%2Fstatic-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatiksoftware%2Fstatic-cache/lists"}