PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Caching » Cache_Lite » Bug #7411

New module Temp.php

Details

Request #7411New module Temp.php
Submitted2006-04-17 15:36 UTC
Fromfnjordy at gmail dot com
StatusWont fix
PackageCache_Lite
PHP Version5.1.2
OSLinux/Debian
Roadmaps(Not assigned)

Comments

[2006-04-17 15:36 UTC] fnjordy at gmail dot com

Description:
------------
For temporary files rather than generic data, I'm using this to manage temporary file uploads, a common example would be file attachments for a webmail program. This saves needed an external crontab to clean up old files.

<?php

/**
* This class extends Cache_Lite for use with temporary files.
*
* @package Cache_Lite
* @version $Id$
* @author Steven McCoy <fnjordy@gmail.com>
*/

require_once('Cache/Lite.php');
class Cache_Lite_Temp extends Cache_Lite
{

// --- Public methods ---

/**
* Constructor
*
* $options is an assoc. To have a look at availables options,
* see the constructor of the Cache_Lite class in 'Cache_Lite.php'
*
* @param array $options options
* @access public
*/
function Cache_Lite_Temp($options)
{
$this->Cache_Lite($options);
}

/**
* Move a file into the cache (c.f. save)
*/
function save($file_name, $id, $group = 'default')
{
if ($this->_caching) {
if (isset($id)) {
$this->_setFileName($id, $group);
}
if ($this->_automaticCleaningFactor>0) {
$rand = rand(1, $this->_automaticCleaningFactor);
if ($rand==1) {
$this->clean(false, 'old');
}
}
return rename($file_name, $this->_file);
}
return false;
}

/**
* Check for id in cache but do not return it (c.f. get)
*/
function exists($id, $group = 'default', $doNotTestCacheValidity = false)
{
$this->_id = $id;
$this->_group = $group;
if ($this->_caching) {
$this->_setFileName($id, $group);
if ($doNotTestCacheValidity) {
if (file_exists($this->_file)) {
return true;
}
} else {
if ((file_exists($this->_file)) && (@filemtime($this->_file) > $this->_refreshTime)) {
return true;
}
}
}
return false;
}

}
?>

Test script:
---------------
None atm.

:(

[2006-04-21 17:25 UTC] fab at php dot net

I'm sorry but I think it's too specific for an integration into Cache_Lite