ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 
 __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 ()
 

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 36 of file Memcached.php.

37 {
38 parent::__construct($config);
39 if (!class_exists(\Memcached::class)) {
40 return;
41 }
42 if ($config->getNodes() === []) {
43 return;
44 }
45 $this->initServer($config);
46 }
initServer(Config $config)
Definition: Memcached.php:98
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Cache\Config\getNodes(), and ILIAS\Cache\Adaptor\Memcached\initServer().

+ 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 69 of file Memcached.php.

69 : void
70 {
71 $this->server->delete($this->buildKey($container, $key), 0);
72 }
buildKey(string $container, string $key)
Definition: BaseAdaptor.php:42
$container
@noRector
Definition: wac.php:37

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey(), and ILIAS\UI\examples\Progress\Bar\server().

+ Here is the call graph for this function:

◆ flush()

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

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 93 of file Memcached.php.

93 : void
94 {
95 $this->server->flush();
96 }

References ILIAS\UI\examples\Progress\Bar\server().

+ Here is the call graph for this function:

◆ flushContainer()

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

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 74 of file Memcached.php.

74 : void
75 {
76 $prefix = $this->buildContainerPrefix($container);
77 foreach ($this->server->getAllKeys() as $key) {
78 if (str_starts_with((string) $key, $prefix)) {
79 $this->server->set($key, false, 0);
80 }
81 }
82 foreach ($this->server->getAllKeys() as $key) {
83 if (str_starts_with((string) $key, $prefix)) {
84 $this->server->get(
85 $key
86 ); // invalidates the key, see https://www.php.net/manual/en/memcached.expiration.php
87 }
88 }
89 $this->server->flushBuffers();
90 // $this->lock(1);// see https://github.com/memcached/memcached/issues/307
91 }
buildContainerPrefix(string $container)
Definition: BaseAdaptor.php:47

References ILIAS\Cache\Adaptor\BaseAdaptor\buildContainerPrefix(), and ILIAS\UI\examples\Progress\Bar\server().

+ 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 59 of file Memcached.php.

59 : ?string
60 {
61 return $this->server->get($this->buildKey($container, $key)) ?: null;
62 }

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey(), and ILIAS\UI\examples\Progress\Bar\server().

+ 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 54 of file Memcached.php.

54 : bool
55 {
56 return $this->server->get($this->buildKey($container, $key)) !== false;
57 }

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey(), and ILIAS\UI\examples\Progress\Bar\server().

+ Here is the call graph for this function:

◆ initServer()

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

Definition at line 98 of file Memcached.php.

98 : void
99 {
100 $this->server = new \Memcached(self::PERSISTENT_ID);
101 $nodes = $config->getNodes();
102 foreach ($nodes as $node) {
103 $this->server->addServer(
104 $node->getHost(),
105 $node->getPort(),
106 $node->getWeight() ?? 100 / count($nodes)
107 );
108 }
109 }

References ILIAS\Cache\Config\getNodes(), and ILIAS\UI\examples\Progress\Bar\server().

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

+ 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 49 of file Memcached.php.

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

References ILIAS\UI\examples\Progress\Bar\server().

+ Here is the call graph for this function:

◆ set()

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

Implements ILIAS\Cache\Adaptor\Adaptor.

Definition at line 64 of file Memcached.php.

64 : void
65 {
66 $this->server->set($this->buildKey($container, $key), $value, $ttl);
67 }

References ILIAS\Cache\Adaptor\BaseAdaptor\buildKey(), and ILIAS\UI\examples\Progress\Bar\server().

+ Here is the call graph for this function:

Field Documentation

◆ $server

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

Definition at line 34 of file Memcached.php.

◆ PERSISTENT_ID

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

Definition at line 33 of file Memcached.php.


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