Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 29... Línea 29...
29
    /**
29
    /**
30
     * @var KeyValueHttpHeader
30
     * @var KeyValueHttpHeader
31
     */
31
     */
32
    private $varyHeaders;
32
    private $varyHeaders;
Línea -... Línea 33...
-
 
33
 
-
 
34
    public function __construct(
-
 
35
        ?CacheStorageInterface $cache = null,
33
 
36
        $defaultTtl = 60,
34
    public function __construct(CacheStorageInterface $cache = null, $defaultTtl, KeyValueHttpHeader $varyHeaders = null)
37
        ?KeyValueHttpHeader $varyHeaders = null,
35
    {
38
    ) {
36
        $this->defaultTtl = $defaultTtl;
39
        $this->defaultTtl = $defaultTtl;
37
        $this->varyHeaders = $varyHeaders;
40
        $this->varyHeaders = $varyHeaders;
38
        parent::__construct($cache);
41
        parent::__construct($cache);
Línea 39... Línea 42...
39
    }
42
    }
40
 
43
 
41
    protected function getCacheKey(RequestInterface $request, KeyValueHttpHeader $varyHeaders = null)
44
    protected function getCacheKey(RequestInterface $request, ?KeyValueHttpHeader $varyHeaders = null)
42
    {
45
    {
43
        if (null === $varyHeaders || $varyHeaders->isEmpty()) {
46
        if (null === $varyHeaders || $varyHeaders->isEmpty()) {
44
            return hash(
47
            return hash(
Línea 93... Línea 96...
93
        }
96
        }
Línea 94... Línea 97...
94
 
97
 
Línea 95... Línea 98...
95
        $response = $response->withoutHeader('Etag')->withoutHeader('Last-Modified');
98
        $response = $response->withoutHeader('Etag')->withoutHeader('Last-Modified');
96
 
99
 
97
        $ttl = $this->defaultTtl;
100
        $ttl = $this->defaultTtl;
98
        if ($request->hasHeader(self::HEADER_TTL)) {
101
        if ($request->hasHeader(static::HEADER_TTL)) {
99
            $ttlHeaderValues = $request->getHeader(self::HEADER_TTL);
102
            $ttlHeaderValues = $request->getHeader(static::HEADER_TTL);
Línea 100... Línea 103...
100
            $ttl = (int)reset($ttlHeaderValues);
103
            $ttl = (int)reset($ttlHeaderValues);
101
        }
104
        }
Línea 102... Línea 105...
102
 
105
 
103
        return new CacheEntry($request->withoutHeader(self::HEADER_TTL), $response, new \DateTime(sprintf('+%d seconds', $ttl)));
106
        return new CacheEntry($request->withoutHeader(static::HEADER_TTL), $response, new \DateTime(sprintf('%+d seconds', $ttl)));
104
    }
107
    }