ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCache Class Reference

Cache class. More...

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

Public Member Functions

 __construct ($a_component, $a_cache_name, $a_use_long_content=false)
 Constructor. More...
 
 isDisabled ()
 Check if cache is disabled Forced if member view is active. More...
 
 setComponent ($a_val)
 Set component. More...
 
 setExpiresAfter ($a_val)
 Set expires after x seconds. More...
 
 getExpiresAfter ()
 Get expires after x seconds. More...
 
 getEntry ($a_id)
 Get entry. More...
 
 getLastAccessStatus ()
 Last access. More...
 
 storeEntry ( $a_id, $a_value, $a_int_key1=null, $a_int_key2=null, $a_text_key1=null, $a_text_key2=null)
 Store entry. More...
 
 deleteByAdditionalKeys ( $a_int_key1=null, $a_int_key2=null, $a_text_key1=null, $a_text_key2=null)
 Delete by additional keys. More...
 
 deleteAllEntries ()
 Delete all entries of cache. More...
 
 deleteEntry ($a_id)
 Delete entry. More...
 

Protected Member Functions

 getComponent ()
 Get component. More...
 
 setName ($a_val)
 Set name. More...
 
 getName ()
 Get name. More...
 
 setUseLongContent ($a_val)
 Set use long content. More...
 
 getUseLongContent ()
 Get use long content. More...
 
 readEntry ($a_id)
 Read entry. More...
 

Detailed Description

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
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters

return

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

27 {
28 $this->setComponent($a_component);
29 $this->setName($a_cache_name);
30 $this->setUseLongContent($a_use_long_content);
31 }
setUseLongContent($a_val)
Set use long content.
setComponent($a_val)
Set component.
setName($a_val)
Set name.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteAllEntries()

ilCache::deleteAllEntries ( )

Delete all entries of cache.

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

275 {
276 global $ilDB;
277
278 $table = $this->getUseLongContent()
279 ? "cache_clob"
280 : "cache_text";
281
282 $q = "DELETE FROM $table WHERE " .
283 "component = " . $ilDB->quote($this->getComponent(), "text") .
284 " AND name = " . $ilDB->quote($this->getName(), "text");
285 $ilDB->manipulate($q);
286 }
getUseLongContent()
Get use long content.
getName()
Get name.
getComponent()
Get component.
if(empty($password)) $table
Definition: pwgen.php:24
global $ilDB

References $ilDB, $table, getComponent(), getName(), and getUseLongContent().

+ Here is the call graph for this function:

◆ deleteByAdditionalKeys()

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

Delete by additional keys.

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

246 {
247 global $ilDB;
248
249 $table = $this->getUseLongContent()
250 ? "cache_clob"
251 : "cache_text";
252
253 $q = "DELETE FROM $table WHERE " .
254 "component = " . $ilDB->quote($this->getComponent(), "text") .
255 " AND name = " . $ilDB->quote($this->getName(), "text");
256
257 $fds = array("int_key_1" => array("v" => $a_int_key1, "t" => "integer"),
258 "int_key_2" => array("v" => $a_int_key2, "t" => "integer"),
259 "text_key_1" => array("v" => $a_text_key1, "t" => "text"),
260 "text_key_2" => array("v" => $a_text_key2, "t" => "text"));
261 $sep = " AND";
262 foreach ($fds as $k => $fd) {
263 if (!is_null($fd["v"])) {
264 $q .= $sep . " " . $k . " = " . $ilDB->quote($fd["v"], $fd["t"]);
265 $set = " AND";
266 }
267 }
268 $ilDB->manipulate($q);
269 }

References $ilDB, $table, getComponent(), getName(), and getUseLongContent().

Referenced by ilCalendarCache\deleteUserEntries().

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

◆ deleteEntry()

ilCache::deleteEntry (   $a_id)

Delete entry.

Parameters
stringkey

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

294 {
295 global $ilDB;
296
297 $table = $this->getUseLongContent()
298 ? "cache_clob"
299 : "cache_text";
300
301 $ilDB->manipulate("DELETE FROM " . $table . " WHERE "
302 . " entry_id = " . $ilDB->quote($a_id, "text")
303 . " AND component = " . $ilDB->quote($this->getComponent(), "text") .
304 " AND name = " . $ilDB->quote($this->getName(), "text"));
305 }

References $ilDB, $table, and getUseLongContent().

+ Here is the call graph for this function:

◆ getComponent()

ilCache::getComponent ( )
protected

Get component.

Returns
string component

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

60 {
61 return $this->component;
62 }

Referenced by deleteAllEntries(), deleteByAdditionalKeys(), readEntry(), and storeEntry().

+ Here is the caller graph for this function:

◆ getEntry()

ilCache::getEntry (   $a_id)
final

Get entry.

Parameters
stringentry id
Returns
string entry value

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

131 {
132 if ($this->readEntry($a_id)) { // cache hit
133 $this->last_access = "hit";
134 return $this->entry;
135 }
136 $this->last_access = "miss";
137 }
readEntry($a_id)
Read entry.

References readEntry().

+ Here is the call graph for this function:

◆ getExpiresAfter()

ilCache::getExpiresAfter ( )

Get expires after x seconds.

Returns
int expires after x seconds

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

120 {
121 return $this->expires_after;
122 }

Referenced by storeEntry().

+ Here is the caller graph for this function:

◆ getLastAccessStatus()

ilCache::getLastAccessStatus ( )

Last access.

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

174 {
175 return $this->last_access;
176 }

◆ getName()

ilCache::getName ( )
protected

Get name.

Returns
string name

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

80 {
81 return $this->name;
82 }

References $name.

Referenced by deleteAllEntries(), deleteByAdditionalKeys(), readEntry(), and storeEntry().

+ Here is the caller graph for this function:

◆ getUseLongContent()

ilCache::getUseLongContent ( )
protected

Get use long content.

Returns
boolean use long content

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

100 {
101 return $this->use_long_content;
102 }

Referenced by deleteAllEntries(), deleteByAdditionalKeys(), deleteEntry(), readEntry(), and storeEntry().

+ Here is the caller graph for this function:

◆ isDisabled()

ilCache::isDisabled ( )

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

Returns
bool

Reimplemented in ilNewsCache, and ilListItemAccessCache.

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

39 {
40 include_once './Services/Container/classes/class.ilMemberViewSettings.php';
41 return ilMemberViewSettings::getInstance()->isActive();
42 }
static getInstance()
Get instance.

References ilMemberViewSettings\getInstance().

+ Here is the call graph for this function:

◆ readEntry()

ilCache::readEntry (   $a_id)
protected

Read entry.

Parameters

return

Reimplemented in ilCalendarCache, ilNewsCache, and ilListItemAccessCache.

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

146 {
147 global $ilDB;
148
149 $table = $this->getUseLongContent()
150 ? "cache_clob"
151 : "cache_text";
152
153 $query = "SELECT value FROM $table WHERE " .
154 "component = " . $ilDB->quote($this->getComponent(), "text") . " AND " .
155 "name = " . $ilDB->quote($this->getName(), "text") . " AND " .
156 "expire_time > " . $ilDB->quote(time(), "integer") . " AND " .
157 "ilias_version = " . $ilDB->quote(ILIAS_VERSION_NUMERIC, "text") . " AND " .
158 "entry_id = " . $ilDB->quote($a_id, "text");
159
160 $set = $ilDB->query($query);
161
162 if ($rec = $ilDB->fetchAssoc($set)) {
163 $this->entry = $rec["value"];
164 return true;
165 }
166
167 return false;
168 }
const ILIAS_VERSION_NUMERIC
$query

References $ilDB, $query, $table, 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 (   $a_val)

Set component.

Parameters
stringcomponent

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

50 {
51 $this->component = $a_val;
52 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setExpiresAfter()

ilCache::setExpiresAfter (   $a_val)

Set expires after x seconds.

Parameters
intexpires after x seconds

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

110 {
111 $this->expires_after = $a_val;
112 }

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

+ Here is the caller graph for this function:

◆ setName()

ilCache::setName (   $a_val)
protected

Set name.

Parameters
stringname

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

70 {
71 $this->name = $a_val;
72 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUseLongContent()

ilCache::setUseLongContent (   $a_val)
protected

Set use long content.

Parameters
booleanuse long content

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

90 {
91 $this->use_long_content = $a_val;
92 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ storeEntry()

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

Store entry.

Parameters
stringkey
stringvalue
intadditional optional integer key
intadditional optional integer key
stringadditional optional text key
stringadditional optional text key
Returns

Reimplemented in ilNewsCache, ilListItemAccessCache, and ilCalendarCache.

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

197 {
198 global $ilDB;
199
200 $table = $this->getUseLongContent()
201 ? "cache_clob"
202 : "cache_text";
203 $type = $this->getUseLongContent()
204 ? "clob"
205 : "text";
206
207 // do not store values, that do not fit into the text field
208 if (strlen($a_value) > 4000 && $type == "text") {
209 return;
210 }
211
212 $set = $ilDB->replace($table, array(
213 "component" => array("text", $this->getComponent()),
214 "name" => array("text", $this->getName()),
215 "entry_id" => array("text", $a_id)
216 ), array(
217 "value" => array($type, $a_value),
218 "int_key_1" => array("integer", $a_int_key1),
219 "int_key_2" => array("integer", $a_int_key2),
220 "text_key_1" => array("text", $a_text_key1),
221 "text_key_2" => array("text", $a_text_key2),
222 "expire_time" => array("integer", (int) (time() + $this->getExpiresAfter())),
223 "ilias_version" => array("text", ILIAS_VERSION_NUMERIC)
224 ));
225
226 // In 1/2000 times, delete old entries
227 $random = new \ilRandom();
228 $num = $random->int(1, 2000);
229 if ($num == 500) {
230 $ilDB->manipulate(
231 "DELETE FROM $table WHERE " .
232 " ilias_version <> " . $ilDB->quote(ILIAS_VERSION_NUMERIC, "text") .
233 " OR expire_time < " . $ilDB->quote(time(), "integer")
234 );
235 }
236 }
getExpiresAfter()
Get expires after x seconds.
$type

References $ilDB, $table, $type, getComponent(), getExpiresAfter(), getName(), getUseLongContent(), and ILIAS_VERSION_NUMERIC.

+ Here is the call graph for this function:

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