Created
June 19, 2012 19:03
-
-
Save tomasklapka/2955922 to your computer and use it in GitHub Desktop.
test_ip_cache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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