Skip to content

Instantly share code, notes, and snippets.

@tomasklapka
Created June 19, 2012 19:03
Show Gist options
  • Save tomasklapka/2955922 to your computer and use it in GitHub Desktop.
Save tomasklapka/2955922 to your computer and use it in GitHub Desktop.
test_ip_cache.php
<?php
if (!($argc > 0 && isset($argv[1]))) {
echo "zadej ip jako 1. parametr";
exit;
}
$ip = $argv[1];
function vytahni_osc($ip) {
// dotaz do db a vytazeni osc podle ip
$osc = rand(10000, 1000000); //... where ip ...
return $osc;
}
//----------------------------------------------------------------------
require __DIR__.'/nette.min.php';
$storage = new Nette\Caching\Storages\FileStorage(__DIR__.'/data');
$cache = new Nette\Caching\Cache($storage);
$osc = $cache->load($ip);
if ($osc === null) {
echo "Pro IP $ip nic nemam v cachi takze refresh\n";
$osc = vytahni_osc($ip);
$cache->save(
$ip,
$osc,
array(
Nette\Caching\Cache::EXPIRE => '+1 hour'
)
);
}
echo "Pro IP $ip mam v cachi: $osc\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment