BufferCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 38
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A expired() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace MatthiasMullie\Scrapbook\Buffered\Utils;
4
5
use MatthiasMullie\Scrapbook\Adapters\Collections\MemoryStore as MemoryStoreCollection;
6
7
/**
8
 * A collection implementation for Buffer.
9
 *
10
 * @author Matthias Mullie <[email protected]>
11
 * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved
12
 * @license LICENSE MIT
13
 */
14
class BufferCollection extends MemoryStoreCollection
15
{
16
    /**
17
     * @var Buffer
18
     */
19
    protected $cache;
20
21
    /**
22
     * @param string $name
23
     */
24
    public function __construct(Buffer $cache, $name)
25
    {
26
        parent::__construct($cache, $name);
27
    }
28
29
    /**
30
     * Check if a key existed in local storage, but is now expired.
31
     *
32
     * Because our local buffer is also just a real cache, expired items will
33
     * just return nothing, which will lead us to believe no such item exists in
34
     * that local cache, and we'll reach out to the real cache (where the value
35
     * may not yet have been expired because that may have been part of an
36
     * uncommitted write)
37
     * So we'll want to know when a value is in local cache, but expired!
38
     *
39
     * @param string $key
40
     *
41
     * @return bool
42
     */
43
    public function expired($key)
44
    {
45
        if (false !== $this->get($key)) {
46
            // returned a value, clearly not yet expired
47
            return false;
48
        }
49
50
        // a known item, not returned by get, is expired
51
        return array_key_exists($key, $this->cache->items);
52
    }
53
}
54