Skip to content

Commit 3f42f59

Browse files
committed
Merge pull request #4 from php-cache/Nyholm-patch-1
Added redis in a comment.
2 parents 8a5843f + 20606fe commit 3f42f59

7 files changed

Lines changed: 49 additions & 29 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This repository has one trait and one interfaces that makes a PSR-6 cache implementation taggable. Using tags allow you
55
to tag related items, and then clear the cached data for that tag only.
66

7-
*Note: Performance will be best with a driver such as memcached, which automatically purges stale records.*
7+
*Note: Performance will be best with a driver such as memcached or redis, which automatically purges stale records.*
88

99
## Usage
1010

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cache/taggable-cache",
33
"type": "library",
4-
"description": "Add tag support to your PSR-6 cache implementation",
4+
"description": "Add tag support to your PSR-6 cache implementation",
55
"keywords": ["cache", "psr6", "tag", "taggable"],
66
"homepage": "https://github.com/php-cache/taggable-cache",
77
"license": "MIT",
@@ -17,7 +17,8 @@
1717
"homepage": "https://github.com/nyholm"
1818
}
1919
],
20-
"require": {
20+
"require":
21+
{
2122
"php": "^5.5|^7",
2223
"psr/cache": "1.0.0"
2324
},

src/TaggablePoolInterface.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313

1414
/**
1515
* Lets you add tags to your cache items. Prepend the PSR-6 function arguments with an array of tag names for
16-
* functions not requiring an CacheItemInterface
16+
* functions not requiring an CacheItemInterface.
1717
*
1818
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
1919
*/
2020
interface TaggablePoolInterface
2121
{
22-
public function getItem($key, array $tags = array());
23-
public function getItems(array $keys = array(), array $tags = array());
24-
public function hasItem($key, array $tags = array());
25-
public function clear(array $tags = array());
26-
public function deleteItem($key, array $tags = array());
27-
public function deleteItems(array $keys, array $tags = array());
22+
public function getItem($key, array $tags = []);
23+
24+
public function getItems(array $keys = [], array $tags = []);
25+
26+
public function hasItem($key, array $tags = []);
27+
28+
public function clear(array $tags = []);
29+
30+
public function deleteItem($key, array $tags = []);
31+
32+
public function deleteItems(array $keys, array $tags = []);
2833
}

src/TaggablePoolTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function flushTag($name)
6767
}
6868

6969
/**
70-
* Generate a good cache key that is dependent of the tags. This key should be the key of the CacheItem
70+
* Generate a good cache key that is dependent of the tags. This key should be the key of the CacheItem.
7171
*
7272
* @param string $key
7373
* @param array $tags
@@ -79,7 +79,7 @@ protected function generateCacheKey($key, array $tags)
7979
// We sort the tags because the order should not matter
8080
sort($tags);
8181

82-
$tagIds = array();
82+
$tagIds = [];
8383
foreach ($tags as $tag) {
8484
$tagIds[] = $this->getTagId($tag);
8585
}

tests/Helper/CacheItem.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
<?php
22

3+
/*
4+
* This file is part of php-cache\taggable-cache package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Cache\Taggable\Tests\Helper;
413

514
use Psr\Cache\CacheItemInterface;
615

716
class CacheItem implements CacheItemInterface
817
{
918
/**
10-
* @var string
19+
* @type string
1120
*/
1221
private $key;
1322

1423
/**
15-
* @var string
24+
* @type string
1625
*/
1726
private $value;
1827

1928
/**
20-
* @var boolean
29+
* @type bool
2130
*/
2231
private $hasValue = false;
2332

2433
/**
25-
*
2634
* @param string $key
2735
*/
2836
public function __construct($key)
@@ -31,8 +39,7 @@ public function __construct($key)
3139
}
3240

3341
/**
34-
*
35-
* @return boolean
42+
* @return bool
3643
*/
3744
public function isHit()
3845
{
@@ -63,7 +70,7 @@ public function get()
6370
public function set($value)
6471
{
6572
$this->hasValue = true;
66-
$this->value = $value;
73+
$this->value = $value;
6774

6875
return $this;
6976
}
@@ -77,6 +84,4 @@ public function expiresAfter($time)
7784
{
7885
// TODO: Implement expiresAfter() method.
7986
}
80-
81-
82-
}
87+
}

tests/Helper/CachePool.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<?php
22

3+
/*
4+
* This file is part of php-cache\taggable-cache package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Cache\Taggable\Tests\Helper;
413

514
use Cache\Taggable\TaggablePoolTrait;
615
use Psr\Cache\CacheItemInterface;
716

817
/**
9-
* A cache pool used in tests
18+
* A cache pool used in tests.
1019
*
1120
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
1221
*/
@@ -15,11 +24,11 @@ class CachePool
1524
use TaggablePoolTrait;
1625

1726
/**
18-
* @var array
27+
* @type array
1928
*/
2029
private $memoryCache;
2130

22-
public function getItem($key, array $tags = array())
31+
public function getItem($key, array $tags = [])
2332
{
2433
$taggedKey = $this->generateCacheKey($key, $tags);
2534

@@ -37,10 +46,10 @@ protected function getTagItem($key)
3746
return $item;
3847
}
3948

40-
4149
public function save(CacheItemInterface $item)
4250
{
43-
$this->memoryCache[$item->getKey()]=$item;
51+
$this->memoryCache[$item->getKey()] = $item;
52+
4453
return true;
4554
}
4655

@@ -53,4 +62,4 @@ public function exposeFlushTag($name)
5362
{
5463
return $this->flushTag($name);
5564
}
56-
}
65+
}

tests/TaggablePoolTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ public function testFlushTag()
4343
$cache->exposeFlushTag('tag');
4444
$this->assertFalse($cache->getItem('foo', ['tag'])->isHit());
4545
}
46-
}
46+
}

0 commit comments

Comments
 (0)