diff --git a/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php b/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php index c897e35..58f125f 100644 --- a/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php +++ b/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php @@ -28,9 +28,19 @@ public function it_should_allow_a_get(FakeCacheStore $cache) $this->get('test'); } + public function it_should_allow_storing_cache_forever(FakeCacheStore $cache, Config $config) + { + $config->get(Argument::any())->shouldBeCalled()->willReturn(10); + $config->get('forrest.storage.store_forever')->shouldBeCalled()->willReturn(true); + $cache->forever(Argument::any(), Argument::any())->shouldBeCalled(); + + $this->put('test', 'value'); + } + public function it_should_allow_a_put(FakeCacheStore $cache, Config $config) { $config->get(Argument::any())->shouldBeCalled()->willReturn(10); + $config->get('forrest.storage.store_forever')->shouldBeCalled()->willReturn(false); $cache->put(Argument::any(), Argument::any(), Argument::type('integer'))->shouldBeCalled(); $this->put('test', 'value'); @@ -57,4 +67,8 @@ public function get($str) public function put($str) { } + + public function forever($str) + { + } } diff --git a/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php b/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php index d61dcaa..8bdd13b 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php +++ b/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php @@ -10,6 +10,8 @@ class LaravelCache extends LaravelStorageProvider { public $minutes = 20; + protected $store_forever; + public $path; protected $cache; @@ -23,6 +25,8 @@ public function __construct(Config $config, Cache $cache) if ($minutes = $config->get('forrest.storage.expire_in')) { $this->minutes = $minutes; } + + $this->store_forever = $config->get('forrest.storage.store_forever'); } /** @@ -35,7 +39,11 @@ public function __construct(Config $config, Cache $cache) */ public function put($key, $value) { - return $this->cache->put($this->path.$key, $value, $this->minutes); + if ($this->store_forever) { + return $this->cache->forever($this->path.$key, $value); + } else { + return $this->cache->put($this->path.$key, $value, $this->minutes); + } } /** diff --git a/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php b/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php index 17fedf0..95b0907 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php @@ -11,6 +11,8 @@ class LaravelCache extends LaravelStorageProvider implements StorageInterface { public $minutes = 20; + protected $store_forever; + public $path; protected $cache; @@ -24,6 +26,8 @@ public function __construct(Config $config, Cache $cache) if ($minutes = $config->get('forrest::config.storage.expire_in')) { $this->minutes = $minutes; } + + $this->store_forever = $config->get('forrest::config.storage.store_forever'); } /** @@ -36,7 +40,11 @@ public function __construct(Config $config, Cache $cache) */ public function put($key, $value) { - return $this->cache->put($this->path.$key, $value, $this->minutes); + if ($this->store_forever) { + return $this->cache->forever($this->path.$key, $value); + } else { + return $this->cache->put($this->path.$key, $value, $this->minutes); + } } /** diff --git a/src/config/config.php b/src/config/config.php index 096217e..e7e3fec 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -56,9 +56,10 @@ * Where do you want to store access tokens fetched from Salesforce */ 'storage' => [ - 'type' => 'session', // 'session' or 'cache' are the two options - 'path' => 'forrest_', // unique storage path to avoid collisions - 'expire_in' => 60, // number of minutes to expire cache/session + 'type' => 'session', // 'session' or 'cache' are the two options + 'path' => 'forrest_', // unique storage path to avoid collisions + 'expire_in' => 60, // number of minutes to expire cache/session + 'store_forever' => false, // never expire cache/session ], /*