|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ownCloud |
|
4
|
|
|
* |
|
5
|
|
|
* @author Robin Appelman |
|
6
|
|
|
* @copyright 2016 Robin Appelman [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* This library is free software; you can redistribute it and/or |
|
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
10
|
|
|
* License as published by the Free Software Foundation; either |
|
11
|
|
|
* version 3 of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This library is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public |
|
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Test\Cache; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class FileCache |
|
27
|
|
|
* |
|
28
|
|
|
* @group DB |
|
29
|
|
|
* |
|
30
|
|
|
* @package Test\Cache |
|
31
|
|
|
*/ |
|
32
|
|
|
class CappedMemoryCache extends \Test_Cache { |
|
33
|
|
|
public function setUp() { |
|
34
|
|
|
parent::setUp(); |
|
35
|
|
|
$this->instance = new \OC\Cache\CappedMemoryCache(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testSetOverCap() { |
|
39
|
|
|
$instance = new \OC\Cache\CappedMemoryCache(3); |
|
40
|
|
|
|
|
41
|
|
|
$instance->set('1', 'a'); |
|
42
|
|
|
$instance->set('2', 'b'); |
|
43
|
|
|
$instance->set('3', 'c'); |
|
44
|
|
|
$instance->set('4', 'd'); |
|
45
|
|
|
$instance->set('5', 'e'); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertFalse($instance->hasKey('1')); |
|
48
|
|
|
$this->assertFalse($instance->hasKey('2')); |
|
49
|
|
|
$this->assertTrue($instance->hasKey('3')); |
|
50
|
|
|
$this->assertTrue($instance->hasKey('4')); |
|
51
|
|
|
$this->assertTrue($instance->hasKey('5')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function testClear() { |
|
|
|
|
|
|
55
|
|
|
$value = 'ipsum lorum'; |
|
56
|
|
|
$this->instance->set('1_value1', $value); |
|
57
|
|
|
$this->instance->set('1_value2', $value); |
|
58
|
|
|
$this->instance->set('2_value1', $value); |
|
59
|
|
|
$this->instance->set('3_value1', $value); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertTrue($this->instance->clear()); |
|
62
|
|
|
$this->assertFalse($this->instance->hasKey('1_value1')); |
|
63
|
|
|
$this->assertFalse($this->instance->hasKey('1_value2')); |
|
64
|
|
|
$this->assertFalse($this->instance->hasKey('2_value1')); |
|
65
|
|
|
$this->assertFalse($this->instance->hasKey('3_value1')); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.