ILIAS  release_8 Revision v8.24
ilCache Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilCache:
+ Collaboration diagram for ilCache:

Public Member Functions

 __construct (string $a_component, string $a_cache_name, bool $a_use_long_content=false)
 
 isDisabled ()
 Check if cache is disabled Forced if member view is active. More...
 
 setComponent (string $a_val)
 
 setExpiresAfter (int $a_val)
 Set expires after x seconds. More...
 
 getExpiresAfter ()
 
 getEntry (string $a_id)
 
 getLastAccessStatus ()
 
 storeEntry (string $a_id, string $a_value, ?int $a_int_key1=null, ?int $a_int_key2=null, ?string $a_text_key1=null, ?string $a_text_key2=null)
 
 deleteByAdditionalKeys (?int $a_int_key1=null, ?int $a_int_key2=null, ?string $a_text_key1=null, ?string $a_text_key2=null)
 
 deleteAllEntries ()
 
 deleteEntry (string $a_id)
 

Protected Member Functions

 getComponent ()
 
 setName (string $a_val)
 
 getName ()
 
 setUseLongContent (bool $a_val)
 
 getUseLongContent ()
 
 readEntry (string $a_id)
 

Protected Attributes

string $entry
 
string $last_access
 
int $expires_after
 
bool $use_long_content
 
string $name
 
string $component
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too. If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Cache class. The cache class stores key/value pairs. Since the primary key is only one text field. It's sometimes necessary to combine parts like "100:200" for user id 100 and ref_id 200.

However sometimes records should be deleted by pars of the main key. For this reason up to two optional additional optional integer and two additional optional text fields can be stored. A derived class may delete records based on the content of this additional keys.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 28 of file class.ilCache.php.

Constructor & Destructor Documentation

◆ __construct()

ilCache::__construct ( string  $a_component,
string  $a_cache_name,
bool  $a_use_long_content = false 
)

Definition at line 37 of file class.ilCache.php.

41 {
42 $this->setComponent($a_component);
43 $this->setName($a_cache_name);
44 $this->setUseLongContent($a_use_long_content);
45 }
setName(string $a_val)
setComponent(string $a_val)
setUseLongContent(bool $a_val)

References setComponent(), setName(), and setUseLongContent().

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteAllEntries()

ilCache::deleteAllEntries ( )

Definition at line 217 of file class.ilCache.php.

217 : void
218 {
219 global $ilDB;
220
221 $table = $this->getUseLongContent()
222 ? "cache_clob"
223 : "cache_text";
224
225 $q = "DELETE FROM $table WHERE " .
226 "component = " . $ilDB->quote($this->getComponent(), "text") .
227 " AND name = " . $ilDB->quote($this->getName(), "text");
228 $ilDB->manipulate($q);
229 }
getUseLongContent()

References $ilDB.

◆ deleteByAdditionalKeys()

ilCache::deleteByAdditionalKeys ( ?int  $a_int_key1 = null,
?int  $a_int_key2 = null,
?string  $a_text_key1 = null,
?string  $a_text_key2 = null 
)

Definition at line 187 of file class.ilCache.php.

192 : void {
193 global $ilDB;
194
195 $table = $this->getUseLongContent()
196 ? "cache_clob"
197 : "cache_text";
198
199 $q = "DELETE FROM $table WHERE " .
200 "component = " . $ilDB->quote($this->getComponent(), "text") .
201 " AND name = " . $ilDB->quote($this->getName(), "text");
202
203 $fds = array("int_key_1" => array("v" => $a_int_key1, "t" => "integer"),
204 "int_key_2" => array("v" => $a_int_key2, "t" => "integer"),
205 "text_key_1" => array("v" => $a_text_key1, "t" => "text"),
206 "text_key_2" => array("v" => $a_text_key2, "t" => "text"));
207 $sep = " AND";
208 foreach ($fds as $k => $fd) {
209 if (!is_null($fd["v"])) {
210 $q .= $sep . " " . $k . " = " . $ilDB->quote($fd["v"], $fd["t"]);
211 $set = " AND";
212 }
213 }
214 $ilDB->manipulate($q);
215 }

◆ deleteEntry()

ilCache::deleteEntry ( string  $a_id)

Definition at line 231 of file class.ilCache.php.

231 : void
232 {
233 global $ilDB;
234
235 $table = $this->getUseLongContent()
236 ? "cache_clob"
237 : "cache_text";
238
239 $ilDB->manipulate("DELETE FROM " . $table . " WHERE "
240 . " entry_id = " . $ilDB->quote($a_id, "text")
241 . " AND component = " . $ilDB->quote($this->getComponent(), "text") .
242 " AND name = " . $ilDB->quote($this->getName(), "text"));
243 }

References $ilDB.

◆ getComponent()

ilCache::getComponent ( )
protected

Definition at line 61 of file class.ilCache.php.

61 : string
62 {
63 return $this->component;
64 }
string $component

References $component.

Referenced by readEntry().

+ Here is the caller graph for this function:

◆ getEntry()

ilCache::getEntry ( string  $a_id)
final

Definition at line 99 of file class.ilCache.php.

99 : ?string
100 {
101 if ($this->readEntry($a_id)) { // cache hit
102 $this->last_access = "hit";
103 return $this->entry;
104 }
105 $this->last_access = "miss";
106 return null;
107 }
readEntry(string $a_id)
string $entry

References $entry, and readEntry().

+ Here is the call graph for this function:

◆ getExpiresAfter()

ilCache::getExpiresAfter ( )

Definition at line 94 of file class.ilCache.php.

94 : int
95 {
97 }
int $expires_after

References $expires_after.

◆ getLastAccessStatus()

ilCache::getLastAccessStatus ( )

Definition at line 134 of file class.ilCache.php.

134 : string
135 {
136 return $this->last_access;
137 }
string $last_access

References $last_access.

◆ getName()

ilCache::getName ( )
protected

Definition at line 71 of file class.ilCache.php.

71 : string
72 {
73 return $this->name;
74 }
string $name

References $name.

Referenced by readEntry().

+ Here is the caller graph for this function:

◆ getUseLongContent()

ilCache::getUseLongContent ( )
protected

Definition at line 81 of file class.ilCache.php.

81 : bool
82 {
84 }
bool $use_long_content

References $use_long_content.

Referenced by readEntry().

+ Here is the caller graph for this function:

◆ isDisabled()

ilCache::isDisabled ( )

Check if cache is disabled Forced if member view is active.

Reimplemented in ilNewsCache, and ilListItemAccessCache.

Definition at line 51 of file class.ilCache.php.

51 : bool
52 {
53 return ilMemberViewSettings::getInstance()->isActive();
54 }

References ilMemberViewSettings\getInstance().

+ Here is the call graph for this function:

◆ readEntry()

ilCache::readEntry ( string  $a_id)
protected

Reimplemented in ilCalendarCache, ilNewsCache, and ilListItemAccessCache.

Definition at line 109 of file class.ilCache.php.

109 : bool
110 {
111 global $ilDB;
112
113 $table = $this->getUseLongContent()
114 ? "cache_clob"
115 : "cache_text";
116
117 $query = "SELECT value FROM $table WHERE " .
118 "component = " . $ilDB->quote($this->getComponent(), "text") . " AND " .
119 "name = " . $ilDB->quote($this->getName(), "text") . " AND " .
120 "expire_time > " . $ilDB->quote(time(), "integer") . " AND " .
121 "ilias_version = " . $ilDB->quote(ILIAS_VERSION_NUMERIC, "text") . " AND " .
122 "entry_id = " . $ilDB->quote($a_id, "text");
123
124 $set = $ilDB->query($query);
125
126 if ($rec = $ilDB->fetchAssoc($set)) {
127 $this->entry = $rec["value"];
128 return true;
129 }
130
131 return false;
132 }
const ILIAS_VERSION_NUMERIC
$query

References $ilDB, $query, getComponent(), getName(), getUseLongContent(), and ILIAS_VERSION_NUMERIC.

Referenced by getEntry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setComponent()

ilCache::setComponent ( string  $a_val)

Definition at line 56 of file class.ilCache.php.

56 : void
57 {
58 $this->component = $a_val;
59 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setExpiresAfter()

ilCache::setExpiresAfter ( int  $a_val)

Set expires after x seconds.

Definition at line 89 of file class.ilCache.php.

89 : void
90 {
91 $this->expires_after = $a_val;
92 }

Referenced by ilExampleCache\__construct(), ilCalendarCache\__construct(), ilNewsCache\__construct(), and ilListItemAccessCache\__construct().

+ Here is the caller graph for this function:

◆ setName()

ilCache::setName ( string  $a_val)
protected

Definition at line 66 of file class.ilCache.php.

66 : void
67 {
68 $this->name = $a_val;
69 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUseLongContent()

ilCache::setUseLongContent ( bool  $a_val)
protected

Definition at line 76 of file class.ilCache.php.

76 : void
77 {
78 $this->use_long_content = $a_val;
79 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ storeEntry()

ilCache::storeEntry ( string  $a_id,
string  $a_value,
?int  $a_int_key1 = null,
?int  $a_int_key2 = null,
?string  $a_text_key1 = null,
?string  $a_text_key2 = null 
)

Reimplemented in ilCalendarCache, ilNewsCache, and ilListItemAccessCache.

Definition at line 139 of file class.ilCache.php.

146 : void {
147 global $ilDB;
148
149 $table = $this->getUseLongContent()
150 ? "cache_clob"
151 : "cache_text";
152 $type = $this->getUseLongContent()
153 ? "clob"
154 : "text";
155
156 // do not store values, that do not fit into the text field
157 if (strlen($a_value) > 4000 && $type == "text") {
158 return;
159 }
160
161 $set = $ilDB->replace($table, array(
162 "component" => array("text", $this->getComponent()),
163 "name" => array("text", $this->getName()),
164 "entry_id" => array("text", $a_id)
165 ), array(
166 "value" => array($type, $a_value),
167 "int_key_1" => array("integer", $a_int_key1),
168 "int_key_2" => array("integer", $a_int_key2),
169 "text_key_1" => array("text", $a_text_key1),
170 "text_key_2" => array("text", $a_text_key2),
171 "expire_time" => array("integer", (time() + $this->getExpiresAfter())),
172 "ilias_version" => array("text", ILIAS_VERSION_NUMERIC)
173 ));
174
175 // In 1/2000 times, delete old entries
176 $random = new \ilRandom();
177 $num = $random->int(1, 2000);
178 if ($num == 500) {
179 $ilDB->manipulate(
180 "DELETE FROM $table WHERE " .
181 " ilias_version <> " . $ilDB->quote(ILIAS_VERSION_NUMERIC, "text") .
182 " OR expire_time < " . $ilDB->quote(time(), "integer")
183 );
184 }
185 }
getExpiresAfter()
$type

Field Documentation

◆ $component

string ilCache::$component
protected

Definition at line 35 of file class.ilCache.php.

Referenced by getComponent().

◆ $entry

string ilCache::$entry
protected

Definition at line 30 of file class.ilCache.php.

Referenced by getEntry().

◆ $expires_after

int ilCache::$expires_after
protected

Definition at line 32 of file class.ilCache.php.

Referenced by getExpiresAfter().

◆ $last_access

string ilCache::$last_access
protected

Definition at line 31 of file class.ilCache.php.

Referenced by getLastAccessStatus().

◆ $name

string ilCache::$name
protected

Definition at line 34 of file class.ilCache.php.

Referenced by getName().

◆ $use_long_content

bool ilCache::$use_long_content
protected

Definition at line 33 of file class.ilCache.php.

Referenced by getUseLongContent().


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