PHP code example of stroker / cache

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

    

stroker / cache example snippets


     'StrokerCache',
     


return [
    'strokercache' => [
        'strategies' => [
            'enabled' => [
                'StrokerCache\Strategy\RouteName' => [
                    'routes' => [
                        'home'
                    ],
                ],
            ],
        ],
    ],
];


return [
    'strokercache' => [
        'strategies' => [
            'enabled' => [
                'StrokerCache\Strategy\RouteName' => [
                    'routes' => [
                        'foo/bar' => [
                            'http_methods' => ['GET'],
                            'params' => ['id' => 60]
                        ]
                    ],
                ],
            ],
        ],
    ],
];


return array(
    'strokercache' => [
        'storage_adapter' => [
            'name' => 'Laminas\Cache\Storage\Adapter\Apc',
        ],
    ],
];


return [
    'strokercache' => [
        'storage_adapter' => [
            'name' => 'filesystem',
            'options' => [
              'cache_dir' => __DIR__ . '/../../data/cache'
            ],
        ],
    ],
];


return [
    'strokercache' => [
        'id_generators' => [
            'plugin_manager' => [
                'invokables' => [
                    'myGenerator' => 'MyNamespace\MyGenerator'
                ],
            ],
        ],
        'id_generator' => 'myGenerator'
    ],
];


return [
    'strokercache' => [
        'strategies' => [
            'plugin_manager' => [
                'invokables' => [
                    'MyNamespace\MyCustomStrategy'
                ],
            ],
        ],
    ],
];


return [
    'strokercache' => [
        'strategies' => [
            'enabled' => [
                'MyNamespace\MyCustomStrategy'
            ],
        ],
    ],
];


return [
    'strokercache' => [
        'enabled' => false        
    ]
];

public function onBootstrap(MvcEvent $e)
{
    $serviceManager = $e->getApplication()->getServiceManager();
    $cacheService = $serviceManager->get('strokercache_service');
    $cacheService->getEventManager()->attach(CacheEvent::EVENT_SAVE, function (CacheEvent $e) {
        $e->setTags(['custom_tag']);
    });
}

public function onBootstrap(MvcEvent $e)
{
    $serviceManager = $e->getApplication()->getServiceManager();
    $logger = new \Laminas\Log\Logger();
    $logger->addWriter(new \Laminas\Log\Writer\Stream('/log/strokercache.log'));
    $cacheService = $serviceManager->get('strokercache_service');
    $cacheService->getEventManager()->attach(CacheEvent::EVENT_SAVE, function (CacheEvent $e) use ($logger) {
        $logger->debug('Saving page to cache with ID: ' . $e->getCacheKey());
    });
}

public function onBootstrap(MvcEvent $e)
{
    $serviceManager = $e->getApplication()->getServiceManager();
    $cacheService = $serviceManager->get('strokercache_service');
    $cacheService->getEventManager()->attach(CacheEvent::EVENT_SHOULDCACHE, function (CacheEvent $e) {
        if ($e->getMvcEvent()->getRequest()->getUri()->getPort() == 8080) {
            $e->stopPropagation(true);
            return false;
        }
        return true;
    }, 1000);
}

public function onBootstrap(MvcEvent $e)
{
    $serviceManager = $e->getApplication()->getServiceManager();
    $cacheService = $serviceManager->get('strokercache_service');
    $cacheService->getEventManager()->attach(CacheEvent::EVENT_LOAD, function (CacheEvent $e) {
        $loggedIn = /* your logic here */;
        if ($loggedIn) {
            $e->stopPropagation(true);
            return false;
        }
    }, 1000);
}

public function onBootstrap(MvcEvent $e)
{
    $serviceManager = $e->getApplication()->getServiceManager();
    $cacheService = $serviceManager->get('strokercache_service');
    $cacheService->getEventManager()->attach(CacheEvent::EVENT_SHOULDCACHE, function (CacheEvent $e) {
        $loggedIn = /* your logic here */;
        if ($loggedIn) {
            $e->stopPropagation(true);
            return false;
        }
    }, 1000);
}