Skip to content

Commit

Permalink
Changing how to disable caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiflett committed Apr 23, 2011
1 parent 73046d8 commit 63d0f73
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions eventbrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,28 @@ public function cache($args)
}

if (isset($args['timeout'])) {
$this->cacheTimeout = $args['timeout'];
if ($args['timeout']) {
$this->cacheTimeout = $args['timeout'];
} else {
$this->cacheDir = '';
$this->cacheTimeout = 0;
}
}
}

protected function request($url, $file)
{
$json = '';

if (file_exists($file) && is_readable($file) && (time() - filemtime($file) < $this->cacheTimeout)) {
$json = file_get_contents($file);
if (!empty($file) {
if (file_exists($file) && is_readable($file) && (time() - filemtime($file) < $this->cacheTimeout)) {
$json = file_get_contents($file);
} else {
$json = file_get_contents($url);
file_put_contents($file, $json);
}
} else {
$json = file_get_contents($url);
file_put_contents($file, $json);
}

return $json;
Expand Down Expand Up @@ -85,10 +94,15 @@ public function __call($method, $args) {
case 'get':
case 'list':
case 'search':
$file = "{$this->cacheDir}/eventbrite-{$hash}";
// Check whether caching is disabled.
if ($this->cacheTimeout) {
$file = "{$this->cacheDir}/eventbrite-{$hash}";
} else {
$file = '';
}
break;
default:
$file = '/dev/null';
$file = '';
break;
}

Expand Down

0 comments on commit 63d0f73

Please sign in to comment.