2017 © Pedro Peláez
 

library cacheware

PSR7 cache headers management middleware

image

juliangut/cacheware

PSR7 cache headers management middleware

  • Friday, September 16, 2016
  • by juliangut
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP version Latest Version License, (*1)

Build status Style Code Quality Code Coverage Total Downloads, (*2)

CacheWare

A PSR7 cache headers management middleware., (*3)

This middleware must be run before session_start has been called so it can prevent PHP session mechanism from automatically send any kind of header to the client (including session cookie and caching)., (*4)

You can use this middleware with juliangut/sessionware which will automatically handle session management., (*5)

Installation

Composer

composer require juliangut/cacheware

Usage

require 'vendor/autoload.php';

use \Jgut\Middleware\CacheWare

$configuration = [
  'limiter' => 'private',
  'expire' => 1800, // 30 minutes
];

$cacheMiddleware = new CacheWare($configuration);

// Get $request and $response from PSR7 implementation
$request = new Request();
$response = new Response();

$response = $cacheMiddleware($request, $response, function() { });

// Response has corresponding cache headers for private cache

Integrated on a Middleware workflow:, (*6)

require 'vendor/autoload.php';

use \Jgut\Middleware\CacheWare

$app = new \YourMiddlewareAwareApplication();
$app->addMiddleware(new CacheWare(['limiter' => 'nocache']));
$app->run();

Config

$cacheMiddleware = new CacheWare([
  'limiter' => null
  'expire' => 180,
]);

limiter

Selects cache limiter type. It's values can be public, private, private_no_expire or nocache. If not provided value defined in ini_set session.cache_limiter will be automatically used (normally 'nocache')., (*7)

Cacheware class has CACHE_* constants for convenience., (*8)

If you want to completely disable cache headers give limiter a value of null., (*9)

expire

Sets the time in seconds for caching. If not provided value defined in ini_set session.cache_expire will be automatically used (normally 180). This setting is ignore when using nocache limiter., (*10)

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before., (*11)

See file CONTRIBUTING.md, (*12)

License

See file LICENSE included with the source code for a copy of the license terms., (*13)

The Versions