public static function getInstance() { if (!self::$mem instanceof Memcache) { self::$mem = new Memcache(); } self::$mem->connect('localhost', 11211); return self::$mem; }
/** * Returns the cursor for the referenced documents as objects * * @param Model $model * @param string $field * @param bool $cachable * * @return array */ protected function referencesMany($model, $field, $cachable = true) { $ref_ids = $this->{$field}; if (!isset($ref_ids[0])) { return []; } if ($this->isMongoId($ref_ids[0])) { foreach ($ref_ids as $key => $value) { $ref_ids[$key] = new MongoId($value); } } if ($cachable && static::$cacheComponent) { $cache_key = 'reference_cache_' . $model . '_' . md5(serialize($ref_ids)); // For the next 6 seconds (0.1 minute), the last retrived value // will be returned from cache =) return static::$cacheComponent->remember($cache_key, 0.1, function () use($model, $ref_ids) { return $model::where(['_id' => ['$in' => $ref_ids]], [], true); }); } elseif ($cachable) { return $model::where(['_id' => ['$in' => $ref_ids]], [], true); } else { return $model::where(['_id' => ['$in' => $ref_ids]]); } }
if (!isset($_GET) || empty($_GET)) { throw new Exception("Paramètres d'image manquants"); } // Bootstrap $Bootstrap = Bootstrap::getInstance(); $Bootstrap->setEnv(ENV); $Bootstrap->loadConfigs(ROOT . '/configs/'); $default = array('src' => false, 'width' => false, 'height' => false, 'mode' => false); extract(array_merge($default, $_GET)); if (!$height) { $height = $width; } if (Config::get('cache.pictures')) { sort($_GET); $cachename = ROOT . 'cache/' . sha1($src . '&' . http_build_query($_GET)); $Cache = new CacheComponent($cachename, '-1 month'); $Cache->open(); } $Image = new ImageComponent(ROOT . 'www' . $src); if ($mode == 'crop') { $Image->thumbnail($width, $height); } elseif ($mode == 'zoom') { $Image->zoom($width, $height); } elseif ($width || $height) { $Image->resize($width, $height); } $Image->show(); if (Config::get('cache.pictures')) { $Cache->close(); } flush();