sessionless-1.x-dev/src/Utility/CacheTool.php

src/Utility/CacheTool.php
<?php

declare(strict_types=1);
namespace Drupal\sessionless\Utility;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;

final class CacheTool {

  /**
   * @param \Closure() $closure
   */
  public static function getOrCompute(CacheBackendInterface $cache, string $cid, \Closure $closure, $expire = Cache::PERMANENT, array $tags = []): mixed {
    $item = $cache->get($cid);
    if ($item) {
      return $item->data;
    }
    $data = $closure();
    $cache->set($cid, $data, $expire, $tags);
    return $data;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc