
In order to migrate IDP from LV 4.x to latest LV version, following task were performed: * Updated namespace to be complain with PSR-4 * General Refactoring: moved all DB access code from services to repositories. * Migration to LV 5.X: these migration guides were applied - https://laravel.com/docs/5.3/upgrade#upgrade-5.0 - https://laravel.com/docs/5.3/upgrade#upgrade-5.1.0 - https://laravel.com/docs/5.3/upgrade#upgrade-5.2.0 * Improved caching: added repositories decorators in order to add REDIS cache to queries, entities Change-Id: I8edf9f5fce6585129701c88bb88332f242307534
163 lines
2.9 KiB
PHP
163 lines
2.9 KiB
PHP
<?php
|
|
|
|
use Utils\Services\ICacheService;
|
|
|
|
class CacheServiceStub implements ICacheService {
|
|
|
|
private static $cache = array();
|
|
|
|
/**
|
|
* Determine if a key exists
|
|
* @param $key
|
|
* @return bool
|
|
*/
|
|
public function exists($key)
|
|
{
|
|
return array_key_exists($key,self::$cache);
|
|
}
|
|
|
|
/**
|
|
* Delete a key
|
|
* @param $key
|
|
* @return mixed
|
|
*/
|
|
public function delete($key)
|
|
{
|
|
if(array_key_exists($key,self::$cache))
|
|
unset(self::$cache[$key]);
|
|
}
|
|
|
|
/**
|
|
* Delete a key
|
|
* @param array $keys
|
|
* @return mixed
|
|
*/
|
|
public function deleteArray(array $keys)
|
|
{
|
|
foreach($keys as $key)
|
|
$this->delete($key);
|
|
}
|
|
|
|
/**
|
|
* retrieves a hash
|
|
* @param $name
|
|
* @param array $values
|
|
* @return array
|
|
*/
|
|
public function getHash($name, array $values)
|
|
{
|
|
if(array_key_exists($name,self::$cache))
|
|
return self::$cache[$name];
|
|
}
|
|
|
|
/**
|
|
* save a hash, with an optional time to live
|
|
* @param $name
|
|
* @param array $values
|
|
* @param int $ttl
|
|
* @return mixed
|
|
*/
|
|
public function storeHash($name, array $values, $ttl = 0)
|
|
{
|
|
self::$cache[$name] = $values;
|
|
}
|
|
|
|
/**
|
|
* @param $counter_name
|
|
* @param int $ttl
|
|
* @return mixed
|
|
*/
|
|
public function incCounter($counter_name, $ttl = 0)
|
|
{
|
|
if(!array_key_exists($counter_name,self::$cache))
|
|
{
|
|
self::$cache[$counter_name] = 0;
|
|
}
|
|
self::$cache[$counter_name] = intval(self::$cache[$counter_name]) + 1;
|
|
}
|
|
|
|
/**
|
|
* @param $counter_name
|
|
* @return mixed
|
|
*/
|
|
public function incCounterIfExists($counter_name)
|
|
{
|
|
if(array_key_exists($counter_name,self::$cache))
|
|
{
|
|
self::$cache[$counter_name] = intval(self::$cache[$counter_name]) + 1;
|
|
}
|
|
}
|
|
|
|
public function addMemberSet($set_name, $member)
|
|
{
|
|
// TODO: Implement addMemberSet() method.
|
|
}
|
|
|
|
public function deleteMemberSet($set_name, $member)
|
|
{
|
|
// TODO: Implement deleteMemberSet() method.
|
|
}
|
|
|
|
public function getSet($set_name)
|
|
{
|
|
if(array_key_exists($set_name,self::$cache)){
|
|
return self::$cache[$set_name];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getSingleValue($key)
|
|
{
|
|
if(array_key_exists($key,self::$cache)){
|
|
return self::$cache[$key];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function setSingleValue($key, $value, $ttl = 0)
|
|
{
|
|
self::$cache[$key]= $value;
|
|
}
|
|
|
|
/**
|
|
* adds a single value if given keys does not exists, with an optional
|
|
* time to live
|
|
* @param $key
|
|
* @param $value
|
|
* @param int $ttl
|
|
* @return mixed
|
|
*/
|
|
public function addSingleValue($key, $value, $ttl = 0)
|
|
{
|
|
if(!array_key_exists($key,self::$cache)){
|
|
self::$cache[$key]= $value;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set time to live to a given key
|
|
* @param $key
|
|
* @param $ttl
|
|
* @return mixed
|
|
*/
|
|
public function setKeyExpiration($key, $ttl)
|
|
{
|
|
// TODO: Implement setKeyExpiration() method.
|
|
}
|
|
|
|
public function boot()
|
|
{
|
|
// TODO: Implement boot() method.
|
|
}
|
|
|
|
/**Returns the remaining time to live of a key that has a timeout.
|
|
* @param string $key
|
|
* @return int
|
|
*/
|
|
public function ttl($key)
|
|
{
|
|
// TODO: Implement ttl() method.
|
|
}
|
|
} |