Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • CachePlugin
  • CallbackCacheKeyProvider
  • CallbackCanCacheStrategy
  • DefaultCacheKeyProvider
  • DefaultCacheStorage
  • DefaultCanCacheStrategy
  • DefaultRevalidation
  • DenyRevalidation
  • SkipRevalidation

Interfaces

  • CacheKeyProviderInterface
  • CacheStorageInterface
  • CanCacheStrategyInterface
  • RevalidationInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Plugin\Cache;
 4: 
 5: use Guzzle\Http\Message\RequestInterface;
 6: 
 7: /**
 8:  * Default cache key strategy that uses all but the body of a request for the key. Add a cache.key_filter parameter to
 9:  * a request to modify what gets cached.
10:  *
11:  * cache.key_filter is a string containing semicolon separated values. Each value contains a comma separated list of
12:  * things to filter from the key. The currently supported filters are 'header' and 'query'. For example, to filter out
13:  * the 'X-Foo' header, the 'X-Bar' header, and the 'test' query string value, set the filter to
14:  * "header=X-Foo,X-Bar; query=test"
15:  */
16: class DefaultCacheKeyProvider implements CacheKeyProviderInterface
17: {
18:     /**
19:      * @var string Request parameter holding the cache key
20:      */
21:     const CACHE_KEY = 'cache.key';
22: 
23:     /**
24:      * @var string Request parameter holding the cache key filter settings
25:      */
26:     const CACHE_KEY_FILTER = 'cache.key_filter';
27: 
28:     /**
29:      * @var string Request parameter holding the raw key
30:      */
31:     const CACHE_KEY_RAW = 'cache.raw_key';
32: 
33:     /**
34:      * {@inheritdoc}
35:      */
36:     public function getCacheKey(RequestInterface $request)
37:     {
38:         // See if the key has already been calculated
39:         $key = $request->getParams()->get(self::CACHE_KEY);
40: 
41:         if (!$key) {
42: 
43:             $cloned = clone $request;
44:             $cloned->removeHeader('Cache-Control');
45: 
46:             // Check to see how and if the key should be filtered
47:             foreach (explode(';', $request->getParams()->get(self::CACHE_KEY_FILTER)) as $part) {
48:                 $pieces = array_map('trim', explode('=', $part));
49:                 if (isset($pieces[1])) {
50:                     foreach (array_map('trim', explode(',', $pieces[1])) as $remove) {
51:                         if ($pieces[0] == 'header') {
52:                             $cloned->removeHeader($remove);
53:                         } elseif ($pieces[0] == 'query') {
54:                             $cloned->getQuery()->remove($remove);
55:                         }
56:                     }
57:                 }
58:             }
59: 
60:             $raw = (string) $cloned;
61:             $key = 'GZ' . md5($raw);
62:             $request->getParams()->set(self::CACHE_KEY, $key)->set(self::CACHE_KEY_RAW, $raw);
63:         }
64: 
65:         return $key;
66:     }
67: }
68: 
php-coveralls API documentation generated by ApiGen 2.8.0