Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbitron committed Jul 15, 2014
1 parent 70793e9 commit 1f1ca7d
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions simpleCache.php → SimpleCache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* SimpleCache v1.3.0
* SimpleCache v1.4.0
*
* By Gilbert Pellegrom
* http://dev7studios.com
Expand All @@ -11,23 +11,16 @@

class SimpleCache {

//Path to cache folder (with trailing /)
var $cache_path = 'cache/';
//Length of time to cache a file in seconds
var $cache_time = 3600;
// possibility of define the file extension
var $cache_extension = '.cache';
// Path to cache folder (with trailing /)
public $cache_path = 'cache/';
// Length of time to cache a file (in seconds)
public $cache_time = 3600;
// Cache file extension
public $cache_extension = '.cache';

//This is just a functionality wrapper function
function get_data($label, $url)
// This is just a functionality wrapper function
public function get_data($label, $url)
{
// append trailing if is missing
$path_size = strlen($this->cache_path);
if (substr($this->cache_path, $path_size - 1) !== '/')
{
$this->cache_path .= '/';
}

if($data = $this->get_cache($label)){
return $data;
} else {
Expand All @@ -37,22 +30,22 @@ function get_data($label, $url)
}
}

function set_cache($label, $data)
public function set_cache($label, $data)
{
file_put_contents($this->cache_path . $this->safe_filename($label) . $this->cache_extension, $data);
}

function get_cache($label)
public function get_cache($label)
{
if($this->is_cached($label)){
$filename = $this->cache_path . $this->safe_filename($label) . $this->cache_extension;
$filename = $this->cache_path . $this->safe_filename($label) . $this->cache_extension;
return file_get_contents($filename);
}

return false;
}

function is_cached($label)
public function is_cached($label)
{
$filename = $this->cache_path . $this->safe_filename($label) . $this->cache_extension;

Expand All @@ -62,13 +55,13 @@ function is_cached($label)
}

//Helper function for retrieving data from url
function do_curl($url)
public function do_curl($url)
{
if(function_exists("curl_init")){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$content = curl_exec($ch);
curl_close($ch);
return $content;
Expand All @@ -78,10 +71,8 @@ function do_curl($url)
}

//Helper function to validate filenames
function safe_filename($filename)
private function safe_filename($filename)
{
return preg_replace('/[^0-9a-z\.\_\-]/i','', strtolower($filename));
}
}

?>

0 comments on commit 1f1ca7d

Please sign in to comment.