ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 isDisabled ()
 Check if cache is disabled Forced if member view is active.
 setComponent ($a_val)
 Set component.
 setExpiresAfter ($a_val)
 Set expires after x seconds.
 getExpiresAfter ()
 Get expires after x seconds.
 getEntry ($a_id)
 Get entry.
 getLastAccessStatus ()
 Last access.
 storeEntry ($a_id, $a_value, $a_int_key1=null, $a_int_key2=null, $a_text_key1=null, $a_text_key2=null)
 Store entry.
 deleteByAdditionalKeys ($a_int_key1=null, $a_int_key2=null, $a_text_key1=null, $a_text_key2=null)
 Delete by additional keys.
 deleteAllEntries ()
 Delete all entries of cache.
 deleteEntry ($a_id)
 Delete entry.

Protected Member Functions

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

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:
class.ilCache.php 23268 2010-03-18 15:20:54Z akill

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

Constructor & Destructor Documentation

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

Constructor.

Parameters
@return

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

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

{
$this->setComponent($a_component);
$this->setName($a_cache_name);
$this->setUseLongContent($a_use_long_content);
}

+ Here is the call graph for this function:

Member Function Documentation

ilCache::deleteAllEntries ( )

Delete all entries of cache.

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

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

{
global $ilDB;
$table = $this->getUseLongContent()
? "cache_clob"
: "cache_text";
$q = "DELETE FROM $table WHERE ".
"component = ".$ilDB->quote($this->getComponent(), "text").
" AND name = ".$ilDB->quote($this->getName(), "text");
$ilDB->manipulate($q);
}

+ Here is the call graph for this function:

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.

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

Referenced by ilListItemAccessCache\deleteByRefId().

{
global $ilDB;
$table = $this->getUseLongContent()
? "cache_clob"
: "cache_text";
$q = "DELETE FROM $table WHERE ".
"component = ".$ilDB->quote($this->getComponent(), "text").
" AND name = ".$ilDB->quote($this->getName(), "text");
$fds = array("int_key_1" => array("v" => $a_int_key1, "t" => "integer"),
"int_key_2" => array("v" => $a_int_key2, "t" => "integer"),
"text_key_1" => array("v" => $a_text_key1, "t" => "text"),
"text_key_2" => array("v" => $a_text_key2, "t" => "text"));
$sep = " AND";
foreach ($fds as $k => $fd)
{
if (!is_null($fd["v"]))
{
$q .= $sep." ".$k." = ".$ilDB->quote($fd["v"], $fd["t"]);
$set = " AND";
}
}
$ilDB->manipulate($q);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCache::deleteEntry (   $a_id)

Delete entry.

Parameters
stringkey

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

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

{
global $ilDB;
$table = $this->getUseLongContent()
? "cache_clob"
: "cache_text";
$ilDB->manipulate("DELETE FROM ".$table." WHERE "
." entry_id = ".$ilDB->quote($a_id, "text")
." AND component = ".$ilDB->quote($this->getComponent(), "text").
" AND name = ".$ilDB->quote($this->getName(), "text"));
}

+ Here is the call graph for this function:

ilCache::getComponent ( )
protected

Get component.

Returns
string component

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

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

{
return $this->component;
}

+ Here is the caller graph for this function:

ilCache::getEntry (   $a_id)
final

Get entry.

Parameters
stringentry id
Returns
string entry value

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

References readEntry().

{
if ($this->readEntry($a_id)) // cache hit
{
$this->last_access = "hit";
return $this->entry;
}
$this->last_access = "miss";
}

+ Here is the call graph for this function:

ilCache::getExpiresAfter ( )

Get expires after x seconds.

Returns
int expires after x seconds

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

Referenced by storeEntry().

{
return $this->expires_after;
}

+ Here is the caller graph for this function:

ilCache::getLastAccessStatus ( )

Last access.

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

{
return $this->last_access;
}
ilCache::getName ( )
protected

Get name.

Returns
string name

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

References $name.

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

{
return $this->name;
}

+ Here is the caller graph for this function:

ilCache::getUseLongContent ( )
protected

Get use long content.

Returns
boolean use long content

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

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

{
return $this->use_long_content;
}

+ Here is the caller graph for this function:

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.

References ilMemberViewSettings\getInstance().

{
include_once './Services/Container/classes/class.ilMemberViewSettings.php';
return ilMemberViewSettings::getInstance()->isActive();
}

+ Here is the call graph for this function:

ilCache::readEntry (   $a_id)
protected

Read entry.

Parameters
@return

Reimplemented in ilNewsCache, ilListItemAccessCache, and ilCalendarCache.

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

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

Referenced by getEntry().

{
global $ilDB;
$table = $this->getUseLongContent()
? "cache_clob"
: "cache_text";
$query = "SELECT value FROM $table WHERE ".
"component = ".$ilDB->quote($this->getComponent(), "text")." AND ".
"name = ".$ilDB->quote($this->getName(), "text")." AND ".
"expire_time > ".$ilDB->quote(time(), "integer")." AND ".
"ilias_version = ".$ilDB->quote(ILIAS_VERSION_NUMERIC, "text")." AND ".
"entry_id = ".$ilDB->quote($a_id, "text");
$set = $ilDB->query($query);
if ($rec = $ilDB->fetchAssoc($set))
{
$this->entry = $rec["value"];
return true;
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCache::setComponent (   $a_val)

Set component.

Parameters
stringcomponent

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

Referenced by __construct().

{
$this->component = $a_val;
}

+ Here is the caller graph for this function:

ilCache::setExpiresAfter (   $a_val)

Set expires after x seconds.

Parameters
intexpires after x seconds

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

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

{
$this->expires_after = $a_val;
}

+ Here is the caller graph for this function:

ilCache::setName (   $a_val)
protected

Set name.

Parameters
stringname

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

Referenced by __construct().

{
$this->name = $a_val;
}

+ Here is the caller graph for this function:

ilCache::setUseLongContent (   $a_val)
protected

Set use long content.

Parameters
booleanuse long content

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

Referenced by __construct().

{
$this->use_long_content = $a_val;
}

+ Here is the caller graph for this function:

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.

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

{
global $ilDB;
$table = $this->getUseLongContent()
? "cache_clob"
: "cache_text";
? "clob"
: "text";
// do not store values, that do not fit into the text field
if (strlen($a_value) > 4000 && $type == "text")
{
return;
}
$set = $ilDB->replace($table, array(
"component" => array("text", $this->getComponent()),
"name" => array("text", $this->getName()),
"entry_id" => array("text", $a_id)
), array (
"value" => array($type, $a_value),
"int_key_1" => array("integer", $a_int_key1),
"int_key_2" => array("integer", $a_int_key2),
"text_key_1" => array("text", $a_text_key1),
"text_key_2" => array("text", $a_text_key2),
"expire_time" => array("integer", (int) (time() + $this->getExpiresAfter())),
"ilias_version" => array("text", ILIAS_VERSION_NUMERIC)
));
// In 1/2000 times, delete old entries
$num = rand(1,2000);
if ($num == 500)
{
$ilDB->manipulate("DELETE FROM $table WHERE ".
" ilias_version <> ".$ilDB->quote(ILIAS_VERSION_NUMERIC, "text").
" OR expire_time < ".$ilDB->quote(time(), "integer")
);
}
}

+ Here is the call graph for this function:


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