Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Increment and decrement tagged cache items #23578

Merged
merged 1 commit into from
Mar 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Illuminate/Cache/RedisTaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ public function put($key, $value, $minutes = null)
parent::put($key, $value, $minutes);
}

/**
* Increment the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function increment($key, $value = 1)
{
$this->pushStandardKeys($this->tags->getNamespace(), $key);

parent::increment($key, $value);
}

/**
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function decrement($key, $value = 1)
{
$this->pushStandardKeys($s->tags->getNamespace(), $key);

parent::decrement($key, $value);
}

/**
* Store an item in the cache indefinitely.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/TaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function increment($key, $value = 1)
}

/**
* Increment the value of an item in the cache.
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
Expand Down
18 changes: 18 additions & 0 deletions tests/Cache/CacheTaggedCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ public function testTagsWithStringArgument()
$this->assertEquals('bar', $store->tags('bop')->get('foo'));
}

public function testTagsWithIncrementCanBeFlushed()
{
$store = new ArrayStore;
$store->tags('bop')->increment('foo', 5);
$this->assertEquals(5, $store->tags('bop')->get('foo'));
$store->tags('bop')->flush();
$this->assertNull($store->tags('bop')->get('foo'));
}

public function testTagsWithDecrementCanBeFlushed()
{
$store = new ArrayStore;
$store->tags('bop')->decrement('foo', 5);
$this->assertEquals(-5, $store->tags('bop')->get('foo'));
$store->tags('bop')->flush();
$this->assertNull($store->tags('bop')->get('foo'));
}

public function testTagsCacheForever()
{
$store = new ArrayStore;
Expand Down