You are here

protected function Formatter::setCachedData in RESTful 7.2

Gets the cached computed value for the fields to be rendered.

Parameters

mixed $data: The data to be rendered.

mixed $output: The rendered data to output.

string[] $parent_hashes: An array that holds the name of the parent cache hashes that lead to the current data structure.

3 calls to Formatter::setCachedData()
FormatterHalJson::extractFieldValues in src/Plugin/formatter/FormatterHalJson.php
Extracts the actual values from the resource fields.
FormatterJson::extractFieldValues in src/Plugin/formatter/FormatterJson.php
Extracts the actual values from the resource fields.
FormatterJsonApi::extractFieldValues in src/Plugin/formatter/FormatterJsonApi.php
Extracts the actual values from the resource fields.

File

src/Plugin/formatter/Formatter.php, line 169
Contains \Drupal\restful\Plugin\formatter\Formatter

Class

Formatter
Class Formatter.

Namespace

Drupal\restful\Plugin\formatter

Code

protected function setCachedData($data, $output, array $parent_hashes = array()) {
  if (!($render_cache = $this
    ->createCacheController($data))) {
    return;
  }
  $render_cache
    ->set($output);

  // After setting the cache for the current object, mark all parent hashes
  // with the current cache fragments. That will have the effect of allowing
  // to clear the parent caches based on the children fragments.
  $fragments = $this
    ->cacheFragments($data);
  foreach ($parent_hashes as $parent_hash) {
    foreach ($fragments as $tag_type => $tag_value) {

      // Check if the fragment already exists.
      $query = new \EntityFieldQuery();
      $duplicate = (bool) $query
        ->entityCondition('entity_type', 'cache_fragment')
        ->propertyCondition('value', $tag_value)
        ->propertyCondition('type', $tag_type)
        ->propertyCondition('hash', $parent_hash)
        ->count()
        ->execute();
      if ($duplicate) {
        continue;
      }
      $cache_fragment = new CacheFragment(array(
        'value' => $tag_value,
        'type' => $tag_type,
        'hash' => $parent_hash,
      ), 'cache_fragment');
      try {
        $cache_fragment
          ->save();
      } catch (\Exception $e) {
        watchdog_exception('restful', $e);
      }
    }
  }
}