Esempio n. 1
0
 /**
  * @param ITypeInterface $Type
  * @param bool           $ForceType
  */
 function __construct(ITypeInterface $Type = null, $ForceType = false)
 {
     if ($Type === null) {
         $Type = new Memcached();
     }
     if (!$ForceType) {
         if (!$Type->isAvailable()) {
             $Type = new Memory();
         }
     }
     $this->Type = $Type;
     if ($this->Type->needConfiguration()) {
         if ($this->Type->getConfiguration() !== null) {
             $ConfigCache = new Memory(__METHOD__);
             $Configuration = $ConfigCache->getValue($this->Type->getConfiguration());
             if (false !== $Configuration) {
                 $this->Type->setConfiguration($Configuration);
             } else {
                 $Configuration = parse_ini_file(__DIR__ . '/Configuration.ini', true);
                 if (isset($Configuration[$this->Type->getConfiguration()])) {
                     $Configuration = $Configuration[$this->Type->getConfiguration()];
                 } else {
                     $Configuration = null;
                 }
                 $ConfigCache->setValue($this->Type->getConfiguration(), $Configuration);
                 $this->Type->setConfiguration($Configuration);
             }
         } else {
             $this->Type->setConfiguration(null);
         }
     }
 }
 /**
  * @param string $Key
  *
  * @return mixed|false
  */
 public function getValue($Key)
 {
     if (null !== self::$Server) {
         $Value = self::$Server->get($Key);
         // 0 = MEMCACHED_SUCCESS
         if (self::$Server->getResultCode() == 0) {
             return $Value;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @param ITypeInterface $Type
  *
  * @throws \Exception
  */
 function __construct(ITypeInterface $Type = null)
 {
     if ($Type === null) {
         $Type = new Memcached();
     }
     if (!$Type->isAvailable()) {
         $Type = new Apcu();
     }
     if (!$Type->isAvailable()) {
         $Type = new Memory();
     }
     $this->Type = $Type;
     if ($this->Type->needConfiguration() && $this->Type->getConfiguration() !== null) {
         $Configuration = parse_ini_file(__DIR__ . '/Configuration.ini', true);
         if (isset($Configuration[$this->Type->getConfiguration()])) {
             $this->Type->setConfiguration($Configuration[$this->Type->getConfiguration()]);
         } else {
             $this->Type->setConfiguration(null);
         }
     }
 }
Esempio n. 4
0
 /**
  * @param string $Key
  *
  * @return mixed|false
  */
 public function getValue($Key)
 {
     $this->Timing = Debugger::getTimeGap();
     if (null !== self::$Server) {
         $Value = self::$Server->get($Key);
         // 0 = MEMCACHED_SUCCESS
         if (self::$Server->getResultCode() == 0) {
             $this->Timing = number_format((Debugger::getTimeGap() - $this->Timing) * 1000, 3, ',', '');
             return $Value;
         }
     }
     $this->Timing = number_format((Debugger::getTimeGap() - $this->Timing) * 1000, 3, ',', '');
     return false;
 }