You are here

public static function Cache::keyFromQuery in Render cache 7.2

Generates a hash from a query object, to be used as part of the cache key.

This smart caching strategy saves Drupal from querying and rendering to HTML when the underlying query is unchanged.

Expensive queries should use the query builder to create the query and then call this function. Executing the query and formatting results should happen in a #pre_render callback.

Note: This function was overridden to provide the D7 version of SelectQueryInterface.

Parameters

\SelectQueryInterface: A select query object.

Return value

string A hash of the query arguments.

1 call to Cache::keyFromQuery()
CacheTest::test_keyFromQuery in tests/src/Cache/CacheTest.php
Tests ::keyFromQuery() method. @covers ::keyFromQuery()

File

src/Cache/Cache.php, line 38
Contains \Drupal\render_cache\Cache\Cache.

Class

Cache
Helper methods for cache.

Namespace

Drupal\render_cache\Cache

Code

public static function keyFromQuery(SelectQueryInterface $query) {
  $query
    ->preExecute();
  $keys = array(
    (string) $query,
    $query
      ->getArguments(),
  );
  return hash('sha256', serialize($keys));
}