Add caching to tracking results
This commit is contained in:
parent
f4ce64a6e8
commit
bacbaf7cac
@ -2,17 +2,32 @@
|
||||
|
||||
$trackinginfo;
|
||||
|
||||
$code = $VARS["code"];
|
||||
$carrier = "";
|
||||
if (!empty($VARS["carrier"])) {
|
||||
$carrier = $VARS["carrier"];
|
||||
}
|
||||
|
||||
try {
|
||||
if (!empty($VARS["carrier"])) {
|
||||
$trackinginfo = Tracking::track($VARS["code"], $VARS["carrier"]);
|
||||
} else {
|
||||
$trackinginfo = Tracking::track($VARS["code"]);
|
||||
$cacheresp = $memcache->get("logistics.tracking.$code.$carrier");
|
||||
if ($cacheresp !== false && empty($VARS["nocache"])) {
|
||||
exitWithJson(json_decode($cacheresp, true));
|
||||
}
|
||||
|
||||
$trackinginfo = Tracking::track($code, $carrier);
|
||||
} catch (TrackingException $ex) {
|
||||
sendJsonResp($ex->getMessage(), "ERROR");
|
||||
$output = [
|
||||
"status" => "ERROR",
|
||||
"msg" => $ex->getMessage()
|
||||
];
|
||||
$memcache->set("logistics.tracking.$code.$carrier", json_encode($output), 60 * 10);
|
||||
exitWithJson($output);
|
||||
}
|
||||
|
||||
if (is_null($trackinginfo)) {
|
||||
sendJsonResp("Could not find any results for that tracking code.", "ERROR");
|
||||
}
|
||||
exitWithJson($trackinginfo->toObject());
|
||||
|
||||
$output = $trackinginfo->toObject();
|
||||
$memcache->set("logistics.tracking.$code.$carrier", json_encode($output), 60 * 60);
|
||||
exitWithJson($output);
|
||||
|
Loading…
x
Reference in New Issue
Block a user