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.8] Honor PSR-16 SimpleCache interface #26726

Merged
merged 6 commits into from
Dec 4, 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
8 changes: 4 additions & 4 deletions src/Illuminate/Cache/ApcStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public function get($key)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
$this->apc->put($this->prefix.$key, $value, (int) ($minutes * 60));
return $this->apc->put($this->prefix.$key, $value, (int) ($minutes * 60));
}

/**
Expand Down Expand Up @@ -90,11 +90,11 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->put($key, $value, 0);
return $this->put($key, $value, 0);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Cache/ArrayStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public function get($key)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
$this->storage[$key] = $value;

return true;
}

/**
Expand Down Expand Up @@ -69,11 +71,11 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->put($key, $value, 0);
return $this->put($key, $value, 0);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Illuminate/Cache/DatabaseStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function get($key)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
Expand All @@ -100,9 +100,11 @@ public function put($key, $value, $minutes)
$expiration = $this->getTime() + (int) ($minutes * 60);

try {
$this->table()->insert(compact('key', 'value', 'expiration'));
return $this->table()->insert(compact('key', 'value', 'expiration'));
} catch (Exception $e) {
$this->table()->where('key', $key)->update(compact('value', 'expiration'));
$result = $this->table()->where('key', $key)->update(compact('value', 'expiration'));

return $result > 0;
}
}

Expand Down Expand Up @@ -196,11 +198,11 @@ protected function getTime()
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->put($key, $value, 5256000);
return $this->put($key, $value, 5256000);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ public function get($key)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
$this->ensureCacheDirectoryExists($path = $this->path($key));

$this->files->put(
$result = $this->files->put(
$path, $this->expiration($minutes).serialize($value), true
);

return $result !== false && $result > 0;
}

/**
Expand Down Expand Up @@ -112,11 +114,11 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->put($key, $value, 0);
return $this->put($key, $value, 0);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Cache/MemcachedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public function many(array $keys)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
$this->memcached->set(
return $this->memcached->set(
$this->prefix.$key, $value, $this->calculateExpiration($minutes)
);
}
Expand All @@ -119,7 +119,7 @@ public function put($key, $value, $minutes)
*
* @param array $values
* @param float|int $minutes
* @return void
* @return bool
*/
public function putMany(array $values, $minutes)
{
Expand All @@ -129,7 +129,7 @@ public function putMany(array $values, $minutes)
$prefixedValues[$this->prefix.$key] = $value;
}

$this->memcached->setMulti(
return $this->memcached->setMulti(
$prefixedValues, $this->calculateExpiration($minutes)
);
}
Expand Down Expand Up @@ -178,11 +178,11 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->put($key, $value, 0);
return $this->put($key, $value, 0);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Illuminate/Cache/NullStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NullStore extends TaggableStore
*/
public function get($key)
{
//
return null;
}

/**
Expand All @@ -30,11 +30,11 @@ public function get($key)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
//
return false;
}

/**
Expand Down Expand Up @@ -66,22 +66,22 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
//
return false;
}

/**
* Remove an item from the cache.
*
* @param string $key
* @return void
* @return bool
*/
public function forget($key)
{
//
return true;
}

/**
Expand Down
20 changes: 14 additions & 6 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,37 @@ public function many(array $keys)
* @param string $key
* @param mixed $value
* @param float|int $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes)
{
$this->connection()->setex(
$result = $this->connection()->setex(
$this->prefix.$key, (int) max(1, $minutes * 60), $this->serialize($value)
);

return $result ? true : false;
}

/**
* Store multiple items in the cache for a given number of minutes.
*
* @param array $values
* @param float|int $minutes
* @return void
* @return bool
*/
public function putMany(array $values, $minutes)
{
$this->connection()->multi();

$resultMany = null;
foreach ($values as $key => $value) {
$this->put($key, $value, $minutes);
$result = $this->put($key, $value, $minutes);
$resultMany = is_null($resultMany) ? $result : $result && $resultMany;
}

$this->connection()->exec();

return $resultMany ?: false;
}

/**
Expand Down Expand Up @@ -158,11 +164,13 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->connection()->set($this->prefix.$key, $this->serialize($value));
$result = $this->connection()->set($this->prefix.$key, $this->serialize($value));

return $result ? true : false;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Cache/RedisTaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class RedisTaggedCache extends TaggedCache
* @param string $key
* @param mixed $value
* @param \DateTime|float|int|null $minutes
* @return void
* @return bool
*/
public function put($key, $value, $minutes = null)
{
$this->pushStandardKeys($this->tags->getNamespace(), $key);

parent::put($key, $value, $minutes);
return parent::put($key, $value, $minutes);
}

/**
Expand Down Expand Up @@ -65,13 +65,13 @@ public function decrement($key, $value = 1)
*
* @param string $key
* @param mixed $value
* @return void
* @return bool
*/
public function forever($key, $value)
{
$this->pushForeverKeys($this->tags->getNamespace(), $key);

parent::forever($key, $value);
return parent::forever($key, $value);
}

/**
Expand Down
Loading