ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
BaseAdaptor.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Cache\Adaptor;
22 
24 
28 abstract class BaseAdaptor implements Adaptor
29 {
30  protected const LOCK_UNTIL = '_lock_until';
31  private string $instance_prefix;
32 
33  public function __construct(protected Config $config)
34  {
35  // generates a unique prefix for the current instance. this is only to prevent collisions when running multiple
36  // ILIAS Instances on the same server. It uses the md5 hash of the current working directory and takes the first
37  // 6 characters. This is not a secure way to generate a prefix, but it is sufficient for this purpose.
38  // It's highly unlikely that two paths will result in the same prefix.
39  $this->instance_prefix = substr(md5(getcwd()), 0, 6);
40  }
41 
42  protected function buildKey(string $container, string $key): string
43  {
44  return $this->buildContainerPrefix($container) . $key;
45  }
46 
47  protected function buildContainerPrefix(string $container): string
48  {
49  return $this->instance_prefix . self::CONTAINER_PREFIX_SEPARATOR . $container . self::CONTAINER_PREFIX_SEPARATOR;
50  }
51 }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
buildContainerPrefix(string $container)
Definition: BaseAdaptor.php:47
__construct(protected Config $config)
Definition: BaseAdaptor.php:33
$container
Definition: wac.php:36