Cache.Class.php 848 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Mall\Framework\Core;
  3. class Cache {
  4. protected static $_instance;
  5. private function __construct(){}
  6. public function connect($storage, $options=array())
  7. {
  8. $cache = FALSE;
  9. $class = 'Mall\\Framework\\Cache\\'.ucwords(strtolower($storage));
  10. if(class_exists($class)) {
  11. $cache = new $class($options);
  12. }
  13. return $cache;
  14. }
  15. public static function getInstance($options = [])
  16. {
  17. $options = $options ?: Config::getInstance()->get('cache');
  18. $storage = $options['storage'] ?: 'Redis';
  19. $key = $storage . md5(implode(',', $options));
  20. if (!isset(self::$_instance[$key])) {
  21. $obj = new self();
  22. self::$_instance[$key] = $obj->connect($storage, $options);
  23. }
  24. return self::$_instance[$key];
  25. }
  26. }