for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the dingtalk.
* User: Ilham Tahir <[email protected]>
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Aplisin\DingTalk\Kernel\Traits;
use Aplisin\DingTalk\Kernel\ServiceContainer;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\Simple\FilesystemCache;
trait InteractsWithCache
{
* @var CacheInterface
protected $cache;
* @return CacheInterface|FilesystemCache
public function getCache()
if ($this->cache) {
return $this->cache;
}
if (property_exists($this, 'app') && $this->app instanceof ServiceContainer
&& isset($this->app['cache']) && $this->app['cache'] instanceof CacheInterface) {
return $this->cache = $this->app['cache'];
return $this->cache = $this->createDefaultCache();
* @param CacheInterface $cache
* @return $this
public function setCache(CacheInterface $cache)
$this->cache = $cache;
return $this;
* @return FilesystemCache
protected function createDefaultCache()
return new FilesystemCache();