Get Weather - Step 9 - Decoupling


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //decoupling:
  2. //changing the inner impl of MemCache without affecting the
  3. //consumers...they get what they need without KNOWING or CARING about
  4. //the inner implementation of MemCache...
  5.  
  6. class MemCache extends BaseCache{
  7.  
  8. //define("MEM_CACHE_SESSION_KEY", "__memcachesessionkey");
  9.  
  10. public function MemCache(){
  11. //some intitialization here...
  12. }
  13.  
  14. public function get($key){
  15. if (!array_key_exists($key, $_SESSION[MEM_CACHE_SESSION_KEY]))
  16. return $_SESSION[MEM_CACHE_SESSION_KEY];
  17.  
  18. //else
  19. echo "Huston we have a problem!";
  20. }
  21.  
  22. public function set($key, $val){
  23. if (array_key_exists($key, $_SESSION[MEM_CACHE_SESSION_KEY]))
  24. echo "Huston...just to let you know that an override occurs here to $key with val: $val";
  25.  
  26. $_SESSION[MEM_CACHE_SESSION_KEY][$key] = $val;
  27. }
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.