/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//performance tuning... class WeatherService{ private $cache; public function WeatherService(){ //some initialization... $cache = new MemCache(); } public function getWeatherInfo($city, $method){ if ($cache->get()[$city]) return $cache->get($city); $this->cache->set($city,$res); if ($methos=="CL") return convertFrToC($res); return $res; } private function convertFrToC($val){ return (($val+40)*5/9)-40; } } class MemCache{ private $mem; public function MemCache(){ //some intitialization here... } public function get(){ return $this->mem; } public function set($key, $val){ echo "putting [$val] in $key"; $this->mem[$key] = $val; } }