Exemplo n.º 1
0
 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)) ?: [];
 }
Exemplo n.º 2
0
 /**
  * Sets the url for the cache server to enable query caching.
  *
  * Only table schema queries are cached at the moment. A general query cache
  * will follow.
  *
  * Example:
  *
  * <code>
  * $config->set_cache("memcached://localhost");
  * $config->set_cache("memcached://localhost",array("expire" => 60));
  * </code>
  *
  * @param string $url Url to your cache server.
  * @param array $options Array of options
  */
 public function set_cache($url, $options = array())
 {
     Cache::initialize($url, $options);
 }
 public function tear_down()
 {
     Cache::flush();
     Cache::initialize(null);
 }
Exemplo n.º 4
0
 public function test_get_works_without_caching_enabled()
 {
     Cache::$adapter = null;
     $this->assert_equals("abcd", $this->cache_get());
 }
 public function testGetWorksWithoutCachingEnabled()
 {
     Cache::$adapter = null;
     $this->assertEquals("abcd", $this->cacheGet());
 }
 /**
  * Statically initializes the global Cache adapter
  *
  * While the static global state is far from ideal, this provides pure compatibility
  * with AR's use of the cache implementation without a deep refactor or BC break
  *
  * @param CacheAdapterInterface $adapter The adapter to use for the cache
  * @param string $namespace An optional namespace to prefix all cache keys with
  * @param int $default_ttl The default expiry/TTL, in seconds, for each cache entry
  * @static
  * @access public
  * @return void
  */
 public static function init(CacheAdapterInterface $adapter, $namespace = null, $default_ttl = null)
 {
     Cache::$adapter = $adapter;
     Cache::$options = [static::OPTION_KEY_NAMESPACE => (string) $namespace, static::OPTION_KEY_EXPIRE => (int) $default_ttl];
 }
Exemplo n.º 7
0
 /**
  * Sets the url for the cache server to enable query caching.
  *
  * Only table schema queries are cached at the moment. A general query cache
  * will follow.
  *
  * Example:
  *
  * <code>
  * $config->setCache("memcached://localhost");
  * $config->setCache("memcached://localhost",array("expire" => 60));
  * </code>
  *
  * @param string $url Url to your cache server.
  * @param array $options Array of options
  */
 public function setCache($url, $options = [])
 {
     Cache::initialize($url, $options);
 }
Exemplo n.º 8
0
 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);
     });
 }
Exemplo n.º 9
0
 /**
  * @expectedException ActiveRecord\CacheException
  * @expectedExceptionMessage Connection refused
  */
 public function test_exception_when_connect_fails()
 {
     Cache::initialize('memcache://127.0.0.1:1234');
 }
Exemplo n.º 10
0
 /**
  * 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);
 }