PHP code example of atiksoftware / static-cache

1. Go to this page and download the library: Download atiksoftware/static-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

atiksoftware / static-cache example snippets


Atiksoftware\StaticCache\LaravelServiceProvider::class,

protected $middlewareGroups = [
    'web' => [
        \Atiksoftware\StaticCache\Middleware\CacheResponse::class,
        /* ... keep the existing middleware here */
    ],
];

protected $routeMiddleware = [
    'static-cache' => \Atiksoftware\StaticCache\Middleware\CacheResponse::class,
    /* ... keep the existing mappings here */
];

Route::middleware('static-cache')->get('/haberler', [\App\Http\Controllers\App\PostController::class, 'index'])->name('posts');
Route::middleware('static-cache')->get('/haberler/kategori/{category:slug}', [\App\Http\Controllers\App\PostController::class, 'by_category'])->scopeBindings()->name('posts.by_category');
Route::middleware('static-cache')->get('/haberler/ilce/{district:slug}', [\App\Http\Controllers\App\PostController::class, 'by_district'])->scopeBindings()->name('posts.by_district');
Route::middleware('static-cache')->get('/haberler/yazar/{user:slug}', [\App\Http\Controllers\App\PostController::class, 'by_user'])->scopeBindings()->name('posts.by_user');
Route::middleware('static-cache')->get('/haber/{post:slug}', [\App\Http\Controllers\App\PostController::class, 'view'])->scopeBindings()->name('post');
Route::middleware('static-cache')->get('/haberler/{tag:name}', [\App\Http\Controllers\App\PostController::class, 'by_tags'])->name('posts.by_tags');


    

    namespace App\Http\Middleware;

    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Atiksoftware\StaticCache\Middleware\CacheResponse as BaseCacheResponse;

    class CacheResponse extends BaseCacheResponse
    {
        protected function shouldCache(Request $request, Response $response)
        {
            // In this example, we don't ever want to cache pages if the
            // URL contains a query string. So we first check for it,
            // then defer back up to the parent's default checks.
            if ($request->getQueryString()) {
                return false;
            }

            return parent::shouldCache($request, $response);
        }
    }
    

php artisan static-cache:clear

php artisan static-cache:clear posts/first-post
php artisan static-cache:clear posts*
php artisan static-cache:clear posts/first*

    php artisan make:middleware CacheResponse