Browse Source

PHPDocs for cache, Format

master
Anton Terekhov 12 years ago
parent
commit
1e0d1aaa38
  1. 35
      cache/Cache.php
  2. 3
      cache/CacheKey.php
  3. 6
      cache/Cacher.php
  4. 59
      cache/MemcacheCache.php
  5. 3
      classes/Format.class.php

35
cache/Cache.php

@ -11,72 +11,71 @@
abstract class Cache
{
/**
* Add an item to the cache
*
*
* @param string $key
* @param mixed $value
* @param int $expire
* @return bool
*/
abstract public function add($key, $value, $expire = 0);
/**
* Decrement item's value
*
*
* @param string $key
* @param int $decrement
* @return bool
*/
abstract public function decrement($key, $decrement = 1);
/**
* Delete item from the cache
*
*
* @param string $key
* @param int $value
* @return bool
*/
abstract public function del($key);
/**
* Flush all existing items
*
*
* @return bool
*/
abstract public function flush();
/**
* Retrieve item from the cache
*
*
* @param mixed $key
* @return mixed
*/
abstract public function get($key);
/**
* Increment item's value
*
*
* @param string $key
* @param int $increment
* @return bool
*/
abstract public function increment($key, $increment = 1);
/**
* Replace value of the existing item
*
*
* @param string $key
* @param mixed $var
* @param mixed $value
* @param int $expire
* @return bool
*/
abstract public function replace($key, $value, $expire = 0);
/**
* Store data in the cache
*
*
* @param string $key
* @param mixed $value
* @param int $expire

3
cache/CacheKey.php

@ -13,7 +13,7 @@ class CacheKey
{
/**
* @var Cacher
* @var Cache
*/
protected $cacher;
@ -62,6 +62,7 @@ class CacheKey
/**
* @param mixed $value
* @return bool
*/
public function set($value)
{

6
cache/Cacher.php

@ -19,6 +19,12 @@ class Cacher
*/
static protected $caches = array();
/**
* @param $cacher
* @param null|string $config
* @return Cache
* @throws InitializationException
*/
static public function get($cacher, $config = null)
{
if (!isset(self::$caches[$cacher])) {

59
cache/MemcacheCache.php

@ -11,31 +11,33 @@
class MemcacheCache extends Cache
{
/**
* @var Memcache
*/
protected $connection = null;
/**
* @var null|string
*/
protected $key_salt = null;
/**
* One hour to live default
*
*
* @var int
*/
protected $expire = 3600;
public function __construct($config)
{
$this->connection = new Memcache();
if (isset($config['key_salt'])) {
$this->key_salt = $config['key_salt'];
unset($config['key_salt']);
}
$required = array('hostname', 'port');
foreach ($config as $c) {
foreach ($required as $option) {
@ -46,10 +48,10 @@ class MemcacheCache extends Cache
$this->connection->addServer($c['hostname'], $c['port']);
}
}
/**
* Add an item to the cache
*
*
* @param string $key
* @param mixed $value
* @param int $expire
@ -59,10 +61,10 @@ class MemcacheCache extends Cache
{
return $this->connection->add($this->getKey($key), $value, null, $this->getExpire($expire));
}
/**
* Decrement item's value
*
*
* @param string $key
* @param int $decrement
* @return bool
@ -71,32 +73,32 @@ class MemcacheCache extends Cache
{
return $this->connection->decrement($this->getKey($key), $decrement);
}
/**
* Delete item from the cache
*
*
* @param string $key
* @param int $value
* @internal param int $value
* @return bool
*/
public function del($key)
{
return $this->connection->delete($this->getKey($key), 0);
}
/**
* Flush all existing items
*
*
* @return bool
*/
public function flush()
{
return $this->connection->flush();
}
/**
* Retrieve item from the cache
*
*
* @param string $key
* @return mixed
*/
@ -104,10 +106,10 @@ class MemcacheCache extends Cache
{
return $this->connection->get($this->getKey($key));
}
/**
* Increment item's value
*
*
* @param string $key
* @param int $increment
* @return bool
@ -116,23 +118,24 @@ class MemcacheCache extends Cache
{
return $this->connection->increment($this->getKey($key), $increment);
}
/**
* Replace value of the existing item
*
*
* @param string $key
* @param mixed $var
* @param mixed $value
* @param int $expire
* @internal param mixed $var
* @return bool
*/
public function replace($key, $value, $expire = 0)
{
return $this->connection->replace($this->getKey($key), $value, null, $this->getExpire($expire));
}
/**
* Store data in the cache
*
*
* @param string $key
* @param mixed $value
* @param int $expire
@ -142,7 +145,7 @@ class MemcacheCache extends Cache
{
return $this->connection->set($this->getKey($key), $value, null, $this->getExpire($expire));
}
/**
* @param string $key
* @return string
@ -151,7 +154,7 @@ class MemcacheCache extends Cache
{
return md5($this->key_salt . $key);
}
public function getExpire($expire)
{
return ($expire > 0) ? $expire : $this->expire;

3
classes/Format.class.php

@ -47,6 +47,7 @@ class Format
* @param mixed $int
* @param bool $currency - показывать валюту
* @param bool $show_decimals - показывать или нет дробную часть
* @return string
*/
static public function int2money($int = 0, $currency = false, $show_decimals = true)
{
@ -169,7 +170,7 @@ class Format
* Преобразует дату в таймстамп.
*
* @param mixed $time
* @return TimeFormat
* @return int|bool
*/
static public function date2int($time)
{

Loading…
Cancel
Save