Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11 from Rentberry/psr16-cache
Browse files Browse the repository at this point in the history
PSR-16 support
  • Loading branch information
Eugene Terentev authored Aug 9, 2018
2 parents b1fc433 + 4c5ca43 commit cf3b74a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"escapestudios/symfony2-coding-standard": "^3.0",
"slevomat/coding-standard": "^4.0",
"friendsofphp/php-cs-fixer": "^2.3",
"monolog/monolog": "^1.23"
"monolog/monolog": "^1.23",
"psr/simple-cache": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 11 additions & 9 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@

namespace Rentberry\MapsUtils\Cache;

use Psr\SimpleCache\CacheInterface;

/**
* Cache service
*/
class Cache
{
/**
* @var \Memcached
* @var CacheInterface
*/
protected $cache;

/**
* @param \Memcached $cache
* @param CacheInterface $cache
*/
public function __construct(\Memcached $cache)
public function __construct(CacheInterface $cache)
{
$this->cache = $cache;
}

/**
* @param CacheInterface $object
* @param CacheableInterface $object
*
* @return false|mixed
*/
public function getData(CacheInterface $object)
public function getData(CacheableInterface $object)
{
$cacheKey = $object->getCacheKey();
$data = $this->cache->get($cacheKey);
$data = $this->cache->get($cacheKey, null);

if ($data !== false) {
if ($data !== null) {
return $data;
}

Expand All @@ -46,11 +48,11 @@ public function getData(CacheInterface $object)
/**
* Force update data in cache
*
* @param CacheInterface $object
* @param CacheableInterface $object
*
* @return false|mixed
*/
public function updateData(CacheInterface $object)
public function updateData(CacheableInterface $object)
{
$cacheKey = $object->getCacheKey();
$data = $object->getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Rentberry\MapsUtils\Cache;

/**
* Interface Cache
* Interface Cacheable
*/
interface CacheInterface
interface CacheableInterface
{
/**
* @return mixed
Expand Down
10 changes: 5 additions & 5 deletions src/Cache/CacheObject.php → src/Cache/CacheableObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Cache object
*/
class CacheObject implements CacheInterface
class CacheableObject implements CacheableInterface
{
/**
* @var string
Expand Down Expand Up @@ -36,9 +36,9 @@ public function getData()
/**
* @param string $cacheKey
*
* @return CacheObject
* @return CacheableObject
*/
public function setCacheKey(string $cacheKey): CacheObject
public function setCacheKey(string $cacheKey): CacheableObject
{
$this->cacheKey = $cacheKey;

Expand All @@ -48,9 +48,9 @@ public function setCacheKey(string $cacheKey): CacheObject
/**
* @param mixed $data
*
* @return CacheObject
* @return CacheableObject
*/
public function setData($data): CacheObject
public function setData($data): CacheableObject
{
$this->data = $data;

Expand Down
4 changes: 2 additions & 2 deletions src/MapsPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use Rentberry\MapsUtils\Cache\Cache;
use Rentberry\MapsUtils\Cache\CacheInterface;
use Rentberry\MapsUtils\Cache\CacheableInterface;
use Rentberry\MapsUtils\Objects\Place;

/**
* MapsPlace
*/
class MapsPlace implements CacheInterface
class MapsPlace implements CacheableInterface
{
public const QUERY_TYPE_ADDRESS = 'address';
public const QUERY_TYPE_PLACE_ID = 'place_id';
Expand Down
4 changes: 2 additions & 2 deletions src/MapsTimezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use Rentberry\MapsUtils\Cache\Cache;
use Rentberry\MapsUtils\Cache\CacheInterface;
use Rentberry\MapsUtils\Cache\CacheableInterface;

/**
* MapsTimezone
*/
class MapsTimezone implements CacheInterface
class MapsTimezone implements CacheableInterface
{
private const LOCATION_ROUND_LEVEL = 3;
/**
Expand Down

0 comments on commit cf3b74a

Please sign in to comment.