{"id":21107240,"url":"https://github.com/glaivepro/cachepage","last_synced_at":"2025-07-08T16:31:32.869Z","repository":{"id":56372816,"uuid":"70158683","full_name":"GlaivePro/CachePage","owner":"GlaivePro","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-23T13:59:39.000Z","size":23,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-13T16:21:50.516Z","etag":null,"topics":["caching","hacktoberfest","laravel","laravel-5-package"],"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/GlaivePro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-06T13:53:06.000Z","updated_at":"2023-09-13T02:05:52.000Z","dependencies_parsed_at":"2022-08-15T17:31:16.419Z","dependency_job_id":null,"html_url":"https://github.com/GlaivePro/CachePage","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlaivePro%2FCachePage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlaivePro%2FCachePage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlaivePro%2FCachePage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlaivePro%2FCachePage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GlaivePro","download_url":"https://codeload.github.com/GlaivePro/CachePage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225449686,"owners_count":17476094,"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","hacktoberfest","laravel","laravel-5-package"],"created_at":"2024-11-20T00:37:15.700Z","updated_at":"2024-11-20T00:37:16.208Z","avatar_url":"https://github.com/GlaivePro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CachePage\n\nLaravel middleware for full page caching.\n\n\n## Table of Contents\n\n- [How do I get this in my app?](#how-do-i-get-this-in-my-app)\n    - [Composer](#composer)\n    - [Binding it to your app](#binding-it-to-your-app)\n- [How do I use it?](#how-do-i-use-it)\n    - [Middleware](#middleware)\n    - [User-specific caching](#user-specific-caching)\n- [Other concerns](#other-concerns)\n    - [Can I skip it?](#can-i-skip-it)\n    - [How to clear the cache?](#how-to-clear-the-cache)\n    - [When should I use it?](#when-should-i-use-it)\n- [Changelog](#changelog)\n- [License](#license)\n\n## How do I get this in my app?\n\n``` bash\n$ composer require glaivepro/cachepage\n```\n\n### Binding it to your app\n\n\u003e Skip this section if you are using package discovery which is default for recent versions of Laravel.\n\nFirt of all you have to register the service provider. \n\nOpen `config/app.php` and find the `providers` key. Add this line to the array.\n\n```php\n\t...\n\tGlaivePro\\CachePage\\CachePageServiceProvider::class,\n\t...\n```\n\nIf you will need to adjust the behaviour of the package, you have to publish the configuration file according to your application. Just execute this artisan command:\n    \n\tphp artisan vendor:publish --provider=\"GlaivePro\\CachePage\\CachePageServiceProvider\"\n\t\nAnd you will have the `config/cachepage.php` file to change whenever this manual tells you to adjust something in the configuration.\n\n\n## How do I use it?\n\n### Middleware\n\nAdd the `gpcachepage` middleware to a route and all responses will be cached for the configured time. By default it's 5 minutes, but you can change it in the configuration.\n\n```php\n    Route::get('/', 'PageController@welcome')-\u003emiddleware('gpcachepage');\n```\n\nThe response will be cached using Laravels `Cache` functionality you should configure it. It will be keyed by requests url and tagged with `gpcachepage` tag (if your cache driver supports tagging).\n\nYou can specify time if you want to. For example, to cache a page for two minutes:\n\n```php\n    Route::get('contacts', 'PageController@contacts')-\u003emiddleware('gpcachepage:120');\n```\n\nOr make a group of routes that cache their responses for 5 minutes:\n\n```php\n    Route::group(['middleware' =\u003e ['gpcachepage:300']], function () {\n        Route::get('about', 'PageController@about');\n        Route::get('policy', 'PageController@policy');\n    });\n```\nFor further advice regarding usage of middlewares you should read the [Laravel documentation about middlewares](https://laravel.com/docs/master/middleware).\n\n\n### User-specific caching\n\nSometimes the page should be different for different users. For example, you might want to display the users name at top - you will want users to see their own name there, not the cached one, right?\n\nYou can do it like this:\n\n```php\n    Route::get('contacts', 'PageController@contacts')-\u003emiddleware('gpcachepage:120,id');\n```\n\nSpecifying time in this case is unavoidable. The key for caching will be something like `id=153\u0026url=http://mypage.com`.\n\nIf you want to key by users role or some other field (or related field), you can try to pass them like this:\n```php\n\tRoute::get('contacts', 'PageController@contacts')-\u003emiddleware('gpcachepage:120,role.name');\n```\n\nThe middleware will then try to get a value from `Auth::user()-\u003erole-\u003ename`.\n\nIf you only want to cache pages for guests, use the key `NULL` like this and caching will be disabled for authenticated users:\n\n```php\n    Route::get('contacts', 'PageController@contacts')-\u003emiddleware('gpcachepage:120,NULL');\n```\n\n\n## Other concerns\n\n### Can I skip it?\n\nIf you want to skip caching and just view a freshly made page, pass `skipcache=true` as a HTTP parameter, for example:\n\n    http://mypage.com/contacts?skipcache=true\n\t\nYou can also use `1` instead of `true` if you prefer it.\n\nIf you are afraid that users might abuse this, you can disable this functionality in configuration like this:\n```php\n\t'allowSkipping' =\u003e false,\n```\n\n\n### How to clear the cache?\n\nIf you want to clear the cached page that you are seeing, specify a true `clearcache` in the HTTP request:\n\n    http://mypage.com/contacts?clearcache=1\n\nThe cache for page that you are seeing will be erased. However, if you are using user-specific caching, other users caches will not be reset. If you don't want this to be possible, you can disable it in the config:\n```php\n\t'allowClearing' =\u003e false,\n```\n\nIf you update something like main menu or make changes to a page that you want all users to see, you can clear all of the cache using `flushcache` in the url.\n\n    http://mypage.com/contacts?flushcache=1\n\t\nThis functionality is dangerous as someone can easily clear your cache all the time therefore it is disabled by default. If you decide to use it, you have to enable it in the configuration like this:\n```php\n\t'allowFlushing' =\u003e true,\n```\n\nBeware! If possible, we use tags for caching. However, if you are using caching driver that does not support tagging, this flushing might clear all of your applications cache.\n\n\n### When should I use it?\n\nFirst of all, decide the maximum allowable caching time for a page. How often does the page change? How soon do you want the changes to be visible? Is it ok that a page will refresh once every minute? Once every 10 minutes? Once a week?\n\nWhen you know the time, try to guess how many users will use a single cache. For example, if you cache a page for 2 minutes, how many users will view it during the time? If the page will receive 100 hits during the 2 minutes, sure it's worth caching. However some old article or a privacy policy page might be viewed less than once every 2 minutes, so no point caching those for 2 minutes as no users would use the cached version.\n\nIf you are using user-specific caching, take into account that as well. If each of your logged-in users see a different page, will they actually do enough hits to make the caching worth it?\n\n## Changelog\n\nIt's [here](CHANGELOG.md).\n\n## License\n\nThis package is licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglaivepro%2Fcachepage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglaivepro%2Fcachepage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglaivepro%2Fcachepage/lists"}