Skip to content

Commit

Permalink
Update to semver.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbitron committed Mar 25, 2014
1 parent 878977d commit dc55a03
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions simpleCache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* SimpleCache v1.3
<?php
/*
* SimpleCache v1.3.0
*
* By Gilbert Pellegrom
* http://dev7studios.com
Expand All @@ -15,7 +15,7 @@ class SimpleCache {
var $cache_path = 'cache/';
//Length of time to cache a file in seconds
var $cache_time = 3600;

//This is just a functionality wrapper function
function get_data($label, $url)
{
Expand All @@ -27,38 +27,38 @@ function get_data($label, $url)
return $data;
}
}

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

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

return false;
}

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

if(file_exists($filename) && (filemtime($filename) + $this->cache_time >= time())) return true;

return false;
}

//Helper function for retrieving data from url
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_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
$content = curl_exec($ch);
curl_close($ch);
Expand All @@ -67,9 +67,9 @@ function do_curl($url)
return file_get_contents($url);
}
}

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

0 comments on commit dc55a03

Please sign in to comment.