PHP code example of maegnes / slim-caching-manager

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

    

maegnes / slim-caching-manager example snippets


	
	# 1. Create Slim instance
	$app = new Slim();
	
	# 2a. Add resource '/fetch/my/resource/' to my cache list
	\SlimCachingManager\ResourceMapper\Base::addResourceWildcard('/fetch/my/resource/', 24);

	# 2b. It's also possible to pass a Array with the resource wildcards
	\SlimCachingManager\ResourceMapper\Base::addResourceWildcard(
		Array(
			// Moderator data and list
			'/fetch/moderator/data/' => 24,
			'/fetch/moderator/list/' => 24,
		)
	);	
	
	# 3. You could also use a middleware. For that simple example i used a before.dispatch hook.
	$app->hook('slim.before.dispatch', function () use ($app, $db) {

		# 4. Create instance of your wished ResourceMapper (ETag() or Lastmodified())
		$cachingManager = new \SlimCachingManager\ResourceMapper\ETag();

		# 5. Inject your ResourceHandler, Slim instance and finally set the headers
		$cachingManager->setHandler(new \SlimCachingManager\ResourceHandler\Textfile())
			->setApplication($app) #6.
			->setHeaders(); #7.

	});