PHP Classes

File: Atto/Cache/Item.php

Recommend this page to a friend!
  Classes of Andrei Alexandru   Simple Cache System   Atto/Cache/Item.php   Download  
File: Atto/Cache/Item.php
Role: Class source
Content type: text/plain
Description: Item for the cache system
Class: Simple Cache System
Store and retrieve cached data in MySQL and files
Author: By
Last change:
Date: 7 years ago
Size: 1,130 bytes
 

Contents

Class file image Download
<?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();
    }
}