fixed messed up commit of file cache driver.

This commit is contained in:
Taylor Otwell 2011-06-18 16:44:34 -05:00
parent a3a9368707
commit fcd6cd77ef
1 changed files with 19 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<?php namespace System\Cache\Driver;
class Memcached implements \System\Cache\Driver {
class File implements \System\Cache\Driver {
/**
* All of the loaded cache items.
@ -34,14 +34,25 @@ public function get($key, $default = null)
return $this->items[$key];
}
$cache = \System\Memcached::instance()->get(\System\Config::get('cache.key').$key);
if ($cache === false)
if ( ! file_exists(APP_PATH.'cache/'.$key))
{
return $default;
}
return $this->items[$key] = $cache;
$cache = file_get_contents(APP_PATH.'cache/'.$key);
// --------------------------------------------------
// Has the cache expired? The UNIX expiration time
// is stored at the beginning of the file.
// --------------------------------------------------
if (time() >= substr($cache, 0, 10))
{
$this->forget($key);
return $default;
}
return $this->items[$key] = unserialize(substr($cache, 10));
}
/**
@ -54,7 +65,7 @@ public function get($key, $default = null)
*/
public function put($key, $value, $minutes)
{
\System\Memcached::instance()->set(\System\Config::get('cache.key').$key, $value, 0, $minutes * 60);
file_put_contents(APP_PATH.'cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX);
}
/**
@ -65,7 +76,7 @@ public function put($key, $value, $minutes)
*/
public function forget($key)
{
\System\Memcached::instance()->delete(\System\Config::get('cache.key').$key);
@unlink(APP_PATH.'cache/'.$key);
}
}