<?php
namespace Atto\Cache;
/**
* Cache Item
*
* @package Atto
*
* @namespace Atto\Cache
* @name Atto\Cache\Item
* @author Andrei Alexandru Romila
* @version v1.0
*/
class Item {
/**
* Time to live
*
* @var integer Number of seconds
*/
protected $timeToLive;
/**
* Creation timestamp
*
* @var integer
*/
protected $creation;
/**
* Any data to be stored
*
* @var mixed
*/
protected $data;
/**
* Cache Item constructor
*
* @param mixed $data
* @param integer $timeToLive In seconds
*/
public function __construct($data, $timeToLive) {
$this->data = $data;
$this->timeToLive = $timeToLive;
$this->creation = time();
}
/**
* Returns the data stored
*
* @return mixed
*/
public function getData() {
return $this->data;
}
/**
* Indicates if the current Item has expired or not
*
* @return boolean
*/
public function expired() {
if ($this->timeToLive < 1) {
return false;
}
return ($this->creation + $this->timeToLive) < time();
}
}
|