PHP code example of danilovl / cache-response-bundle

1. Go to this page and download the library: Download danilovl/cache-response-bundle 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/ */

    

danilovl / cache-response-bundle example snippets


#[CacheResponseAttribute(
    key: 'index', 
    expiresAfter: 60, 
    useSession: true, 
    useRoute: true, 
    useQuery: true, 
    useRequest: true,
    useEnv: true
)]
public function index(Request $request): Response
{
    return new Response('content');
}

#[CacheResponseAttribute(
    key: __METHOD__, 
    expiresAfter: 60, 
    useQuery: true, 
    useRequest: true,
    useEnv: true
)]
public function index(Request $request): Response
{
    return new Response('content');
}

#[CacheResponseAttribute(factory: CachKeyFactoryClass::class)]
public function index(Request $request): Response
{
    return new Response('content');
}

0 => "danilovl.cache_response.8414b2ff0a6fafcddc0f42d6d5a5b908d34925c3"
1 => "danilovl.cache_response.8414b2ff08997b2bd029eaab1a04598a500a0034"

0 => "danilovl.cache_response.5f9cf7121290f93c"
1 => "danilovl.cache_response.a202b43aa495f0f3"

$this->eventDispatcher->dispatch(new ClearCacheResponseAllEvent);

$this->eventDispatcher->dispatch(new ClearCacheResponseKeyEvent('cache_key'));
 php

// config/bundles.php

return [
    // ...
    Danilovl\CacheResponseBundle\CacheResponseBundle::class => ['all' => true]
];