public function test_get_does_not_execute_closure_on_cache_hit() { $this->cache_get(); Cache::get("1337", function () { throw new Exception("I better not execute!"); }); }
public function testGetDoesNotExecuteClosureOnCacheHit() { $this->cacheGet(); Cache::get("1337", function () { throw new Exception("I better not execute!"); }); }
public function getTargetUserIds($ar_list_id) { $positive = $negative = []; if ($list = ArList::find($ar_list_id)) { if ($sqls = $list->sqls) { foreach ($sqls as $sql) { if ($sqlStatement = $sql->sql) { $users = Cache::get(md5($sqlStatement), function () use($sqlStatement) { return User::find_by_sql(strtolower($sqlStatement)); //strtolower to make table name lowercase }); if (!empty($users)) { foreach ($users as $user) { if ($user_id = $user->user_id) { if ($sql->type === 'positive') { $positive[$user_id] = 1; } elseif ($sql->type === 'negative') { $negative[$user_id] = 1; } } } } } } } } return array_diff(array_keys($positive), array_keys($negative)) ?: []; }
private function getMetaData() { // as more adapters are added probably want to do this a better way // than using instanceof but gud enuff for now $quote_name = !$this->conn instanceof Pgsql; $table_name = $this->getFullyQualifiedTableName($quote_name); $conn = $this->conn; $this->columns = Cache::get("getMetaData-{$table_name}", function () use($conn, $table_name) { return $conn->columns($table_name); }); }
/** * Will look up a list of primary keys from cache * * @param array $pks An array of primary keys * @return array */ protected static function getModelsFromCache(array $pks) { $models = []; $table = static::table(); foreach ($pks as $pk) { $options = ['conditions' => static::pkConditions($pk)]; $models[] = Cache::get($table->cacheKeyForModel($pk), function () use($table, $options) { $res = $table->find($options); return $res ? $res[0] : null; }, $table->cache_model_expire); } return \array_filter($models); }