CODE STYLE class.fileCache.php
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class.memcached.php
|
* class.memcached.php
|
||||||
|
*
|
||||||
* @package workflow.engine.ProcessMaker
|
* @package workflow.engine.ProcessMaker
|
||||||
*
|
*
|
||||||
* ProcessMaker Open Source Edition
|
* ProcessMaker Open Source Edition
|
||||||
@@ -24,17 +26,21 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FileCache {
|
class FileCache
|
||||||
|
{
|
||||||
|
|
||||||
function __construct($dir) {
|
function __construct ($dir)
|
||||||
|
{
|
||||||
$this->dir = $dir;
|
$this->dir = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _name($key) {
|
private function _name ($key)
|
||||||
|
{
|
||||||
return sprintf( "%s/%s", $this->dir, sha1( $key ) );
|
return sprintf( "%s/%s", $this->dir, sha1( $key ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key, $expiration = 3600) {
|
public function get ($key, $expiration = 3600)
|
||||||
|
{
|
||||||
|
|
||||||
if (! is_dir( $this->dir ) or ! is_writable( $this->dir )) {
|
if (! is_dir( $this->dir ) or ! is_writable( $this->dir )) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -62,8 +68,7 @@ class FileCache {
|
|||||||
|
|
||||||
if (filesize( $cache_path ) > 0) {
|
if (filesize( $cache_path ) > 0) {
|
||||||
$cache = unserialize( fread( $fp, filesize( $cache_path ) ) );
|
$cache = unserialize( fread( $fp, filesize( $cache_path ) ) );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$cache = NULL;
|
$cache = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +78,8 @@ class FileCache {
|
|||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set($key, $data) {
|
public function set ($key, $data)
|
||||||
|
{
|
||||||
|
|
||||||
if (! is_dir( $this->dir ) or ! is_writable( $this->dir )) {
|
if (! is_dir( $this->dir ) or ! is_writable( $this->dir )) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -88,8 +94,7 @@ class FileCache {
|
|||||||
if (flock( $fp, LOCK_EX )) {
|
if (flock( $fp, LOCK_EX )) {
|
||||||
fwrite( $fp, serialize( $data ) );
|
fwrite( $fp, serialize( $data ) );
|
||||||
flock( $fp, LOCK_UN );
|
flock( $fp, LOCK_UN );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
fclose( $fp );
|
fclose( $fp );
|
||||||
@@ -97,7 +102,8 @@ class FileCache {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clear($key) {
|
public function clear ($key)
|
||||||
|
{
|
||||||
$cache_path = $this->_name( $key );
|
$cache_path = $this->_name( $key );
|
||||||
|
|
||||||
if (file_exists( $cache_path )) {
|
if (file_exists( $cache_path )) {
|
||||||
|
|||||||
Reference in New Issue
Block a user