Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace Kevinrob\GuzzleCache\Strategy;
4
 
5
use Kevinrob\GuzzleCache\KeyValueHttpHeader;
6
use Kevinrob\GuzzleCache\Storage\CacheStorageInterface;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
 
10
/**
11
 * This strategy represents a "public" or "shared" HTTP client.
12
 * You can share the storage between applications.
13
 *
14
 * For example, a response with cache-control header "private, max-age=60"
15
 * will be NOT cached by this strategy.
16
 *
17
 * The rules applied are from RFC 7234.
18
 *
19
 * @see https://tools.ietf.org/html/rfc7234
20
 */
21
class PublicCacheStrategy extends PrivateCacheStrategy
22
{
23
    public function __construct(CacheStorageInterface $cache = null)
24
    {
25
        parent::__construct($cache);
26
 
27
        array_unshift($this->ageKey, 's-maxage');
28
    }
29
 
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function getCacheObject(RequestInterface $request, ResponseInterface $response)
34
    {
35
        $cacheControl = new KeyValueHttpHeader($response->getHeader('Cache-Control'));
36
        if ($cacheControl->has('private')) {
37
            return;
38
        }
39
 
40
        return parent::getCacheObject($request, $response);
41
    }
42
}