ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 271 of file class.ilCache.php.

272 {
273 global $ilDB;
274
275 $table = $this->getUseLongContent()
276 ? "cache_clob"
277 : "cache_text";
278
279 $q = "DELETE FROM $table WHERE ".
280 "component = ".$ilDB->quote($this->getComponent(), "text").
281 " AND name = ".$ilDB->quote($this->getName(), "text");
282 $ilDB->manipulate($q);
283 }
getUseLongContent()
Get use long content.
getName()
Get name.
getComponent()
Get component.
global $ilDB

References $ilDB, 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 239 of file class.ilCache.php.

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

References $ilDB, 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 290 of file class.ilCache.php.

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

References $ilDB, 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 {
134 $this->last_access = "hit";
135 return $this->entry;
136 }
137 $this->last_access = "miss";
138 }
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 175 of file class.ilCache.php.

176 {
177 return $this->last_access;
178 }

◆ getName()

ilCache::getName ( )
protected

Get name.

Returns
string name

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

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

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

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

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 (   $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 ilCalendarCache.

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

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

References $ilDB, 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: