Created
July 12, 2013 23:00
-
-
Save asilbalaban/5988491 to your computer and use it in GitHub Desktop.
Look for cache
If cache file exist Return data from cache If data not cached
Select data from database and cache
Return data
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
function select ( $query ) | |
{ | |
$cacheFile = md5($query).'.html'; | |
$cache = 'cache/'.$cacheFile; | |
$cacheSuresi = 60*60*24*7; # one week | |
if (time() - $cacheSuresi < @filemtime($cache)) | |
{ | |
$cacheOku = fopen($cache, 'r'); | |
$sonuc = fgets($cacheOku); | |
fclose($cacheOku); | |
} | |
else | |
{ | |
@unlink ($cache); | |
$sql = mysql_query($query); | |
$say = mysql_num_rows($sql); | |
if ( $say == 0 ) | |
return false; | |
while ( $oku = mysql_fetch_assoc($sql) ) | |
{ | |
$bilgi[] = $oku; | |
} | |
$sonuc = serialize ( $bilgi ); | |
$yaz = fopen($cache, "w+"); | |
fwrite($yaz, $sonuc); | |
fclose($yaz); | |
} | |
return unserialize ( $sonuc ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment