Last active
February 8, 2016 03:44
-
-
Save akira345/760b53dbb37699b90f91 to your computer and use it in GitHub Desktop.
PHPのPear_Cache_Liteのサンプルコードです。
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 | |
include_once "Cache/Lite.php"; | |
//キャッシュの生存時間は8時間 | |
$option = array( | |
"cacheDir" => "./cache/", | |
"lifeTime" => "28800" | |
); | |
$cache = new Cache_Lite($option); | |
function hoge($in_year,$in_month,$cache) { | |
$cache_id = $in_year . $in_month; //キャッシュID。キャッシュする対象を識別するもの。 | |
$group_name="hoge"; //キャッシュグループID。同一キャッシュIDかつ同一キャッシュグループIDで識別される。 | |
if($cache_data = $cache->get($cache_id,$group_name)){ | |
//キャッシュヒット | |
echo "HIT!!"; | |
return $cache_data; | |
} else { | |
//キャッシュミス | |
echo "MISS!"; | |
//データ作成 | |
$tmp = ""; | |
$tmp = "<SELECT name=nengetu> \n"; | |
for($cnt_year = 2000;$cnt_year < 2021;++$cnt_year){ | |
for($cnt_month = 1;$cnt_month < 13;++$cnt_month){ | |
if(($cnt_year == $in_year) && ($cnt_month == $in_month)){ | |
$tmp .= "<OPTION value=\"" . $cnt_year . "/" . $cnt_month . "\" selected>" . $cnt_year . "年" . $cnt_month . "月" . "</OPTION>\n"; | |
} else { | |
$tmp .= "<OPTION value=\"" . $cnt_year . "/" . $cnt_month . "\">" . $cnt_year . "年" . $cnt_month . "月" . "</OPTION>\n"; | |
} | |
} | |
} | |
$tmp .= "</SELECT>\n"; | |
//キャッシュに保存 | |
$cache->save($tmp); | |
return $tmp; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
</head> | |
<title> | |
Cache Sample | |
</title> | |
<body> | |
<form> | |
<?php echo hoge($_GET["year"],$_GET["month"],$cache); ?> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment