8000 [13.x] `Cache::touch()` & `Store::touch()` for TTL Extension by yitzwillroth · Pull Request #55954 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[13.x] Cache::touch() & Store::touch() for TTL Extension #55954

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
:clean: remove inadvertent inclusions
  • Loading branch information
Yitz Willroth committed Jun 9, 2025
commit 485efd0f176248def96c3bdf18ee39d298197ffe
3 changes: 1 addition & 2 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ protected function getPayload($key)
}

$expire = substr($contents, 0, 10);
} catch (Exception $e) {
} catch (Exception) {
return $this->emptyPayload();
}

Expand All @@ -328,7 +328,6 @@ protected function getPayload($key)
try {
$data = unserialize(substr($contents, 10));
} catch (Exception) {

$this->forget($key);

return $this->emptyPayload();
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ protected function serialize($value)
* Determine if the given value should be stored as plain value.
*
* @param mixed $value
* @return bool
*/
protected function shouldBeStoredWithoutSerialization($value): bool
{
Expand Down
18 changes: 17 additions & 1 deletion src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function missing($key)
*
* @param array|string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null): mixed
{
Expand Down Expand Up @@ -250,6 +251,8 @@ public function put($key, $value, $ttl = null)

/**
* {@inheritdoc}
*
* @return bool
*/
public function set($key, $value, $ttl = null): bool
{
Expand All @@ -259,6 +262,7 @@ public function set($key, $value, $ttl = null): bool
/**
* Store multiple items in the cache for a given number of seconds.
*
* @param array $values
* @param \DateTimeInterface|\DateInterval|int|null $ttl
* @return bool
*/
Expand Down Expand Up @@ -292,6 +296,7 @@ public function putMany(array $values, $ttl = null)
/**
* Store multiple items in the cache indefinitely.
*
* @param array $values
* @return bool
*/
protected function putManyForever(array $values)
Expand Down Expand Up @@ -526,7 +531,7 @@ public function flexible($key, $ttl, $callback, $lock = null)
public function touch(string $key, \DateTimeInterface|\DateInterval|int|null $ttl = null): bool
{
$value = $this->get($key);

if (is_null($value)) {
return false;
}
Expand Down Expand Up @@ -557,6 +562,8 @@ public function forget($key)

/**
* {@inheritdoc}
*
* @return bool
*/
public function delete($key): bool
{
Expand All @@ -565,6 +572,8 @@ public function delete($key): bool

/**
* {@inheritdoc}
*
* @return bool
*/
public function deleteMultiple($keys): bool
{
Expand All @@ -581,6 +590,8 @@ public function deleteMultiple($keys): bool

/**
* {@inheritdoc}
*
* @return bool
*/
public function clear(): bool
{
Expand Down Expand Up @@ -742,6 +753,7 @@ public function getEventDispatcher()
/**
* Set the event dispatcher instance.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function setEventDispatcher(Dispatcher $events)
Expand All @@ -753,6 +765,7 @@ public function setEventDispatcher(Dispatcher $events)
* Determine if a cached value exists.
*
* @param string $key
* @return bool
*/
public function offsetExists($key): bool
{
Expand All @@ -763,6 +776,7 @@ public function offsetExists($key): bool
* Retrieve an item from the cache by key.
*
* @param string $key
* @return mixed
*/
public function offsetGet($key): mixed
{
Expand All @@ -774,6 +788,7 @@ public function offsetGet($key): mixed
*
* @param string $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value): void
{
Expand All @@ -784,6 +799,7 @@ public function offsetSet($key, $value): void
* Remove an item from the cache.
*
* @param string $key
* @return void
*/
public function offsetUnset($key): void
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Cache/CacheApcStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,4 @@ public function testFlushesCached()
$result = $store->flush();
$this->assertTrue($result);
}


}
8 changes: 2 additions & 6 deletions tests/Cache/CacheRedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,10 @@ public function testTouchMethodProperlyCallsRedis(): void

public function testForgetMethodProperlyCallsRedis()
{
$key = 'key';

$redis = $this->getRedis();

$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('del')->once()->with("prefix:$key");

$redis->forget($key);
$redis->getRedis()->shouldReceive('del')->once()->with('prefix:foo');
$redis->forget('foo');
}

public function testFlushesCached()
Expand Down
0