ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 31 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 40 of file class.ilCache.php.

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

44  {
45  $this->setComponent($a_component);
46  $this->setName($a_cache_name);
47  $this->setUseLongContent($a_use_long_content);
48  }
setUseLongContent(bool $a_val)
setName(string $a_val)
setComponent(string $a_val)
+ Here is the call graph for this function:

Member Function Documentation

◆ deleteAllEntries()

ilCache::deleteAllEntries ( )

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

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

220  : void
221  {
222  global $ilDB;
223 
224  $table = $this->getUseLongContent()
225  ? "cache_clob"
226  : "cache_text";
227 
228  $q = "DELETE FROM $table WHERE " .
229  "component = " . $ilDB->quote($this->getComponent(), "text") .
230  " AND name = " . $ilDB->quote($this->getName(), "text");
231  $ilDB->manipulate($q);
232  }
$q
Definition: shib_logout.php:21
getUseLongContent()
+ Here is the call graph for this function:

◆ 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 190 of file class.ilCache.php.

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

Referenced by ilCalendarCache\deleteUserEntries().

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

◆ deleteEntry()

ilCache::deleteEntry ( string  $a_id)

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

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

234  : void
235  {
236  global $ilDB;
237 
238  $table = $this->getUseLongContent()
239  ? "cache_clob"
240  : "cache_text";
241 
242  $ilDB->manipulate("DELETE FROM " . $table . " WHERE "
243  . " entry_id = " . $ilDB->quote($a_id, "text")
244  . " AND component = " . $ilDB->quote($this->getComponent(), "text") .
245  " AND name = " . $ilDB->quote($this->getName(), "text"));
246  }
getUseLongContent()
+ Here is the call graph for this function:

◆ getComponent()

ilCache::getComponent ( )
protected

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

References $component.

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

64  : string
65  {
66  return $this->component;
67  }
string $component
+ Here is the caller graph for this function:

◆ getEntry()

ilCache::getEntry ( string  $a_id)
final

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

References $entry, null, and readEntry().

102  : ?string
103  {
104  if ($this->readEntry($a_id)) { // cache hit
105  $this->last_access = "hit";
106  return $this->entry;
107  }
108  $this->last_access = "miss";
109  return null;
110  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
string $entry
readEntry(string $a_id)
+ Here is the call graph for this function:

◆ getExpiresAfter()

ilCache::getExpiresAfter ( )

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

References $expires_after.

Referenced by storeEntry().

97  : int
98  {
99  return $this->expires_after;
100  }
int $expires_after
+ Here is the caller graph for this function:

◆ getLastAccessStatus()

ilCache::getLastAccessStatus ( )

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

References $last_access.

137  : string
138  {
139  return $this->last_access;
140  }
string $last_access

◆ getName()

ilCache::getName ( )
protected

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

References $name.

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

74  : string
75  {
76  return $this->name;
77  }
string $name
+ Here is the caller graph for this function:

◆ getUseLongContent()

ilCache::getUseLongContent ( )
protected

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

References $use_long_content.

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

84  : bool
85  {
87  }
bool $use_long_content
+ Here is the caller graph for this function:

◆ isDisabled()

ilCache::isDisabled ( )

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

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

References ilMemberViewSettings\getInstance().

54  : bool
55  {
56  return ilMemberViewSettings::getInstance()->isActive();
57  }
+ Here is the call graph for this function:

◆ readEntry()

ilCache::readEntry ( string  $a_id)
protected

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

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

Referenced by getEntry().

112  : bool
113  {
114  global $ilDB;
115 
116  $table = $this->getUseLongContent()
117  ? "cache_clob"
118  : "cache_text";
119 
120  $query = "SELECT value FROM $table WHERE " .
121  "component = " . $ilDB->quote($this->getComponent(), "text") . " AND " .
122  "name = " . $ilDB->quote($this->getName(), "text") . " AND " .
123  "expire_time > " . $ilDB->quote(time(), "integer") . " AND " .
124  "ilias_version = " . $ilDB->quote(ILIAS_VERSION_NUMERIC, "text") . " AND " .
125  "entry_id = " . $ilDB->quote($a_id, "text");
126 
127  $set = $ilDB->query($query);
128 
129  if ($rec = $ilDB->fetchAssoc($set)) {
130  $this->entry = $rec["value"];
131  return true;
132  }
133 
134  return false;
135  }
const ILIAS_VERSION_NUMERIC
getUseLongContent()
+ 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 59 of file class.ilCache.php.

Referenced by __construct().

59  : void
60  {
61  $this->component = $a_val;
62  }
+ Here is the caller graph for this function:

◆ setExpiresAfter()

ilCache::setExpiresAfter ( int  $a_val)

Set expires after x seconds.

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

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

92  : void
93  {
94  $this->expires_after = $a_val;
95  }
+ Here is the caller graph for this function:

◆ setName()

ilCache::setName ( string  $a_val)
protected

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

Referenced by __construct().

69  : void
70  {
71  $this->name = $a_val;
72  }
+ Here is the caller graph for this function:

◆ setUseLongContent()

ilCache::setUseLongContent ( bool  $a_val)
protected

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

Referenced by __construct().

79  : void
80  {
81  $this->use_long_content = $a_val;
82  }
+ 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 
)

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

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

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

Field Documentation

◆ $component

string ilCache::$component
protected

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

Referenced by getComponent().

◆ $entry

string ilCache::$entry
protected

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

Referenced by getEntry().

◆ $expires_after

int ilCache::$expires_after
protected

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

Referenced by getExpiresAfter().

◆ $last_access

string ilCache::$last_access
protected

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

Referenced by getLastAccessStatus().

◆ $name

string ilCache::$name
protected

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

Referenced by getName().

◆ $use_long_content

bool ilCache::$use_long_content
protected

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

Referenced by getUseLongContent().


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