Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Silently ignoring TTL if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Burns committed Jan 12, 2017
1 parent b5f1e97 commit d19db90
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 57 deletions.
33 changes: 10 additions & 23 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Zend\Cache\Storage\Plugin;
use Zend\Cache\Storage\PostEvent;
use Zend\Cache\Storage\StorageInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\EventsCapableInterface;
Expand Down Expand Up @@ -1596,17 +1595,11 @@ public function get($key, $default = null)
*/
public function set($key, $value, $ttl = null)
{
if ($ttl && ! $this instanceof TtlUsedAtWriteTimeInterface) {
throw new BadMethodCallException('TTL not supported by cache adapter');
}
if (null !== $ttl) {
$previousTtl = $this->getOptions()->getTtl();
$this->getOptions()->setTtl($ttl);
$result = $this->setItem($key, $value);
$this->getOptions()->setTtl($previousTtl);
return $result;
}
return $this->setItem($key, $value);
$previousTtl = $this->getOptions()->getTtl();
$this->getOptions()->setTtl($ttl);
$result = $this->setItem($key, $value);
$this->getOptions()->setTtl($previousTtl);
return $result;
}

/**
Expand Down Expand Up @@ -1649,17 +1642,11 @@ public function getMultiple($keys, $default = null)
*/
public function setMultiple($values, $ttl = null)
{
if ($ttl && ! $this instanceof TtlUsedAtWriteTimeInterface) {
throw new BadMethodCallException('TTL not supported by cache adapter');
}
if (null !== $ttl) {
$previousTtl = $this->getOptions()->getTtl();
$this->getOptions()->setTtl($ttl);
$result = $this->setItems($values);
$this->getOptions()->setTtl($previousTtl);
return $result;
}
return ! $this->setItems($values);
$previousTtl = $this->getOptions()->getTtl();
$this->getOptions()->setTtl($ttl);
$result = $this->setItems($values);
$this->getOptions()->setTtl($previousTtl);
return $result;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\IterableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class Apc extends AbstractAdapter implements
AvailableSpaceCapableInterface,
ClearByNamespaceInterface,
ClearByPrefixInterface,
FlushableInterface,
IterableInterface,
TotalSpaceCapableInterface,
TtlUsedAtWriteTimeInterface
TotalSpaceCapableInterface
{
/**
* Buffered total space in bytes
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/Adapter/Apcu.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\IterableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class Apcu extends AbstractAdapter implements
AvailableSpaceCapableInterface,
ClearByNamespaceInterface,
ClearByPrefixInterface,
FlushableInterface,
IterableInterface,
TotalSpaceCapableInterface,
TtlUsedAtWriteTimeInterface
TotalSpaceCapableInterface
{
/**
* Buffered total space in bytes
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/Adapter/Memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
use Zend\Cache\Storage\Capabilities;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class Memcache extends AbstractAdapter implements
AvailableSpaceCapableInterface,
FlushableInterface,
TotalSpaceCapableInterface,
TtlUsedAtWriteTimeInterface
TotalSpaceCapableInterface
{
/**
* Has this instance been initialized
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
use Zend\Cache\Storage\Capabilities;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class Memcached extends AbstractAdapter implements
AvailableSpaceCapableInterface,
FlushableInterface,
TotalSpaceCapableInterface,
TtlUsedAtWriteTimeInterface
TotalSpaceCapableInterface
{
/**
* Has this instance be initialized
Expand Down
3 changes: 1 addition & 2 deletions src/Storage/Adapter/MongoDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
use Zend\Cache\Exception;
use Zend\Cache\Storage\Capabilities;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class MongoDb extends AbstractAdapter implements FlushableInterface, TtlUsedAtWriteTimeInterface
class MongoDb extends AbstractAdapter implements FlushableInterface
{
/**
* Has this instance be initialized
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/Adapter/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
use Zend\Cache\Storage\Capabilities;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class Redis extends AbstractAdapter implements
ClearByNamespaceInterface,
ClearByPrefixInterface,
FlushableInterface,
TotalSpaceCapableInterface,
TtlUsedAtWriteTimeInterface
TotalSpaceCapableInterface
{
/**
* Has this instance be initialized
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/Adapter/WinCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
use Zend\Cache\Storage\Capabilities;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\TtlUsedAtWriteTimeInterface;

class WinCache extends AbstractAdapter implements
AvailableSpaceCapableInterface,
FlushableInterface,
TotalSpaceCapableInterface,
TtlUsedAtWriteTimeInterface
TotalSpaceCapableInterface
{
/**
* Constructor
Expand Down
14 changes: 0 additions & 14 deletions src/Storage/TtlUsedAtWriteTimeInterface.php

This file was deleted.

0 comments on commit d19db90

Please sign in to comment.