Posted By

orenus on 06/30/10


Tagged

php oop getweather Lesson2


Versions (?)

Get Weather - Step 5 - Improving performance


 / Published in: PHP
 

  1. //performance tuning...
  2. class WeatherService{
  3.  
  4. private $cache;
  5.  
  6. public function WeatherService(){
  7. //some initialization...
  8. $cache = new MemCache();
  9. }
  10.  
  11. public function getWeatherInfo($city, $method){
  12.  
  13. if ($cache->get()[$city])
  14. return $cache->get($city);
  15.  
  16. $res = shell_exec("./getWdr.sh {$city}");
  17.  
  18. $this->cache->set($city,$res);
  19.  
  20. if ($methos=="CL")
  21. return convertFrToC($res);
  22.  
  23. return $res;
  24. }
  25.  
  26. private function convertFrToC($val){
  27. return (($val+40)*5/9)-40;
  28. }
  29.  
  30. }
  31.  
  32.  
  33. class MemCache{
  34.  
  35. private $mem;
  36.  
  37. public function MemCache(){
  38. //some intitialization here...
  39. $mem = array();
  40. }
  41.  
  42. public function get(){
  43. return $this->mem;
  44. }
  45.  
  46. public function set($key, $val){
  47. echo "putting [$val] in $key";
  48. $this->mem[$key] = $val;
  49. }
  50. }

Report this snippet  

You need to login to post a comment.