ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\Cache\Adaptor\Memcached Class Reference
+ Inheritance diagram for ILIAS\Cache\Adaptor\Memcached:
+ Collaboration diagram for ILIAS\Cache\Adaptor\Memcached:

Public Member Functions

 __construct (Config $config)
 
 isAvailable ()
 
 has (string $container, string $key)
 
 get (string $container, string $key)
 
 set (string $container, string $key, string $value, int $ttl)
 
 delete (string $container, string $key)
 
 flushContainer (string $container)
 
 flush ()
 
- Public Member Functions inherited from ILIAS\Cache\Adaptor\BaseAdaptor
 __construct (protected Config $config)
 

Protected Member Functions

 initServer (Config $config)
 
- Protected Member Functions inherited from ILIAS\Cache\Adaptor\BaseAdaptor
 buildKey (string $container, string $key)
 
 buildContainerPrefix (string $container)
 

Private Attributes

const PERSISTENT_ID = 'ilias_cache'
 
Memcached $server = null
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Cache\Adaptor\Adaptor
const CONTAINER_PREFIX_SEPARATOR = ':'
 
- Protected Attributes inherited from ILIAS\Cache\Adaptor\BaseAdaptor
const LOCK_UNTIL = '_lock_until'
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 28 of file Memcached.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Cache\Adaptor\Memcached::__construct ( Config  $config)

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 33 of file Memcached.php.

References ILIAS\MetaData\Repository\Validation\Data\__construct(), ILIAS\Cache\Config\getNodes(), and ILIAS\Cache\Adaptor\Memcached\initServer().

34  {
35  parent::__construct($config);
36  if (!class_exists(\Memcached::class)) {
37  return;
38  }
39  if ($config->getNodes() === []) {
40  return;
41  }
42  $this->initServer($config);
43  }
__construct(VocabulariesInterface $vocabularies)
initServer(Config $config)
Definition: Memcached.php:95
+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

ILIAS\Cache\Adaptor\Memcached::delete ( string  $container,
string  $key 
)

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 66 of file Memcached.php.

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey().

66  : void
67  {
68  $this->server->delete($this->buildKey($container, $key), 0);
69  }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
$container
Definition: wac.php:14
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ flush()

ILIAS\Cache\Adaptor\Memcached::flush ( )

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 90 of file Memcached.php.

90  : void
91  {
92  $this->server->flush();
93  }

◆ flushContainer()

ILIAS\Cache\Adaptor\Memcached::flushContainer ( string  $container)

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 71 of file Memcached.php.

References ILIAS\LTI\ToolProvider\$key, and ILIAS\Cache\Adaptor\BaseAdaptor\buildContainerPrefix().

71  : void
72  {
73  $prefix = $this->buildContainerPrefix($container);
74  foreach ($this->server->getAllKeys() as $key) {
75  if (str_starts_with($key, $prefix)) {
76  $this->server->set($key, false, 0);
77  }
78  }
79  foreach ($this->server->getAllKeys() as $key) {
80  if (str_starts_with($key, $prefix)) {
81  $this->server->get(
82  $key
83  ); // invalidates the key, see https://www.php.net/manual/en/memcached.expiration.php
84  }
85  }
86  $this->server->flushBuffers();
87  // $this->lock(1);// see https://github.com/memcached/memcached/issues/307
88  }
buildContainerPrefix(string $container)
Definition: BaseAdaptor.php:47
$container
Definition: wac.php:14
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ get()

ILIAS\Cache\Adaptor\Memcached::get ( string  $container,
string  $key 
)

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 56 of file Memcached.php.

References ILIAS\LTI\ToolProvider\$key, and ILIAS\Cache\Adaptor\BaseAdaptor\buildKey().

56  : ?string
57  {
58  return $this->server->get($this->buildKey($container, $key)) ?: null;
59  }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
$container
Definition: wac.php:14
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ has()

ILIAS\Cache\Adaptor\Memcached::has ( string  $container,
string  $key 
)

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 51 of file Memcached.php.

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey().

51  : bool
52  {
53  return $this->server->get($this->buildKey($container, $key)) !== false;
54  }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
$container
Definition: wac.php:14
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ initServer()

ILIAS\Cache\Adaptor\Memcached::initServer ( Config  $config)
protected

Definition at line 95 of file Memcached.php.

References ILIAS\Cache\Config\getNodes().

Referenced by ILIAS\Cache\Adaptor\Memcached\__construct().

95  : void
96  {
97  $this->server = new \Memcached(self::PERSISTENT_ID);
98  $nodes = $config->getNodes();
99  foreach ($nodes as $node) {
100  $this->server->addServer(
101  $node->getHost(),
102  $node->getPort(),
103  $node->getWeight() ?? 100 / count($nodes)
104  );
105  }
106  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAvailable()

ILIAS\Cache\Adaptor\Memcached::isAvailable ( )

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 46 of file Memcached.php.

46  : bool
47  {
48  return class_exists(\Memcached::class) && $this->server !== null && $this->server->getVersion() !== false;
49  }

◆ set()

ILIAS\Cache\Adaptor\Memcached::set ( string  $container,
string  $key,
string  $value,
int  $ttl 
)

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 61 of file Memcached.php.

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey().

61  : void
62  {
63  $this->server->set($this->buildKey($container, $key), $value, $ttl);
64  }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
$container
Definition: wac.php:14
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

Field Documentation

◆ $server

Memcached ILIAS\Cache\Adaptor\Memcached::$server = null
private

Definition at line 31 of file Memcached.php.

◆ PERSISTENT_ID

const ILIAS\Cache\Adaptor\Memcached::PERSISTENT_ID = 'ilias_cache'
private

Definition at line 30 of file Memcached.php.


The documentation for this class was generated from the following file: