ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilGlobalCacheDBLayer Class Reference

Class ilGlobalCacheDBLayer. More...

+ Collaboration diagram for ilGlobalCacheDBLayer:

Public Member Functions

 getWhere ($field, $value, $case_sensitive=true)
 
 filter (array $data, $field, $value, $case_sensitive=true, $strip=true)
 
 where ($field, $value, $case_sensitive=true)
 
 get ($strip=true)
 
 setCachedResults ($cached_results)
 
 getCachedResults ()
 
 setRawData ($raw_data)
 
 getRawData ()
 
 setTableName ($table_name)
 
 getTableName ()
 
 setLoaded ($loaded)
 
 getLoaded ()
 
 setComponent ($component)
 
 getComponent ()
 
 setTtl ($ttl)
 
 getTtl ()
 

Static Public Member Functions

static getInstance ($component, $table_name)
 

Protected Member Functions

 __construct ($component, $table_name, $ttl=NULL)
 
 readFromCache ()
 
 writeToCache ()
 
 updateCachedResults ()
 

Protected Attributes

 $component = ''
 
 $loaded = false
 
 $table_name = ''
 
 $raw_data = array()
 
 $cached_results = array()
 
 $ttl = NULL
 
 $global_cache
 
 $wheres = array()
 

Static Protected Attributes

static $instances = array()
 

Detailed Description

Class ilGlobalCacheDBLayer.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 10 of file class.ilGlobalCacheDBLayer.php.

Constructor & Destructor Documentation

◆ __construct()

ilGlobalCacheDBLayer::__construct (   $component,
  $table_name,
  $ttl = NULL 
)
protected
Parameters
$component
$table_name
int$ttl

Definition at line 55 of file class.ilGlobalCacheDBLayer.php.

References $component, $table_name, $ttl, ilGlobalCache\getInstance(), getLoaded(), readFromCache(), setComponent(), setLoaded(), setTableName(), setTtl(), and writeToCache().

+ Here is the call graph for this function:

Member Function Documentation

◆ filter()

ilGlobalCacheDBLayer::filter ( array  $data,
  $field,
  $value,
  $case_sensitive = true,
  $strip = true 
)
Parameters
array$data
$field
$value
bool$case_sensitive
bool$strip
Returns
array

Definition at line 128 of file class.ilGlobalCacheDBLayer.php.

128 {
129 if (is_array($value)) {
130 $index = md5(serialize($value)) . $case_sensitive;
131 } else {
132 $index = $value . $case_sensitive;
133 }
134 if (isset($this->cached_results[$this->getTableName()][$field][$index])) {
135 return $this->cached_results[$this->getTableName()][$field][$index];
136 }
137 $result = array();
138 foreach ($data as $dat) {
139 if ($case_sensitive) {
140 if (is_array($value)) {
141 if (in_array($dat->{$field}, $value)) {
142 $result[] = $dat;
143 }
144 } elseif ($dat->{$field} == $value) {
145
146 $result[] = $dat;
147 }
148 } else {
149 if (is_array($value)) {
150 if (preg_grep("/" . $dat->{$field} . "/i", $value)) {
151 $result[] = $dat;
152 }
153 } elseif (strcasecmp($dat->{$field}, $value) == 0) {
154 $result[] = $dat;
155 }
156 }
157 }
158 if (count($result) == 1 AND $strip) {
159 $result = $result[0];
160 }
161
162 $this->cached_results[$this->getTableName()][$field][$index] = $result;
163 $this->updateCachedResults();
164
165 return $result;
166 }
$result
$data

References $data, $result, and getTableName().

Referenced by getWhere().

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

◆ get()

ilGlobalCacheDBLayer::get (   $strip = true)
Parameters
bool$strip
Returns
array

Definition at line 197 of file class.ilGlobalCacheDBLayer.php.

197 {
198 $result = $this->getRawData();
199 foreach ($this->wheres as $ilGcDbWhere) {
200 $result = $this->filter($result, $ilGcDbWhere->getField(), $ilGcDbWhere->getValue(), $ilGcDbWhere->getCaseSensitive(), false);
201 }
202
203 if (count($result) == 1 AND $strip) {
204 // echo '<pre>' . print_r($result, 1) . '</pre>';
205 $result = $result[0];
206 }
207
208 return $result;
209 }
filter(array $data, $field, $value, $case_sensitive=true, $strip=true)

References $result.

◆ getCachedResults()

ilGlobalCacheDBLayer::getCachedResults ( )
Returns
array

Definition at line 238 of file class.ilGlobalCacheDBLayer.php.

◆ getComponent()

ilGlobalCacheDBLayer::getComponent ( )
Returns
string

Definition at line 302 of file class.ilGlobalCacheDBLayer.php.

302 {
303 return $this->component;
304 }

◆ getInstance()

static ilGlobalCacheDBLayer::getInstance (   $component,
  $table_name 
)
static
Parameters
$component
$table_name
Returns
ilGlobalCacheDBLayer

Definition at line 218 of file class.ilGlobalCacheDBLayer.php.

218 {
219 if (! isset(self::$instances[$component . $table_name])) {
220 self::$instances[$component . $table_name] = new self($component, $table_name);
221 }
222
223 return self::$instances[$component . $table_name];
224 }

◆ getLoaded()

ilGlobalCacheDBLayer::getLoaded ( )
Returns
boolean

Definition at line 286 of file class.ilGlobalCacheDBLayer.php.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getRawData()

ilGlobalCacheDBLayer::getRawData ( )
Returns
array

Definition at line 254 of file class.ilGlobalCacheDBLayer.php.

Referenced by getWhere(), and writeToCache().

+ Here is the caller graph for this function:

◆ getTableName()

ilGlobalCacheDBLayer::getTableName ( )
Returns
string

Definition at line 270 of file class.ilGlobalCacheDBLayer.php.

270 {
271 return $this->table_name;
272 }

Referenced by filter(), readFromCache(), and writeToCache().

+ Here is the caller graph for this function:

◆ getTtl()

ilGlobalCacheDBLayer::getTtl ( )
Returns
int

Definition at line 318 of file class.ilGlobalCacheDBLayer.php.

318 {
319 return $this->ttl;
320 }

Referenced by writeToCache().

+ Here is the caller graph for this function:

◆ getWhere()

ilGlobalCacheDBLayer::getWhere (   $field,
  $value,
  $case_sensitive = true 
)
Parameters
$field
$value
bool$case_sensitive
Returns
array

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

112 {
113 return $this->filter($this->getRawData(), $field, $value, $case_sensitive);
114 }

References filter(), and getRawData().

+ Here is the call graph for this function:

◆ readFromCache()

ilGlobalCacheDBLayer::readFromCache ( )
protected

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

69 {
70 if ($this->global_cache->isActive()) {
71 $data = $this->global_cache->get($this->getTableName() . '_raw_data');
72 $cached_results = $this->global_cache->get($this->getTableName() . '_cached_results');
73 if (is_array($data)) {
74 $this->setRawData($data);
76 $this->setLoaded(true);
77 }
78 }
79 }

References $cached_results, $data, getTableName(), setCachedResults(), setLoaded(), and setRawData().

Referenced by __construct().

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

◆ setCachedResults()

ilGlobalCacheDBLayer::setCachedResults (   $cached_results)
Parameters
array$cached_results

Definition at line 230 of file class.ilGlobalCacheDBLayer.php.

230 {
231 $this->cached_results = $cached_results;
232 }

Referenced by readFromCache().

+ Here is the caller graph for this function:

◆ setComponent()

ilGlobalCacheDBLayer::setComponent (   $component)
Parameters
string$component

Definition at line 294 of file class.ilGlobalCacheDBLayer.php.

294 {
295 $this->component = $component;
296 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setLoaded()

ilGlobalCacheDBLayer::setLoaded (   $loaded)
Parameters
boolean$loaded

Definition at line 278 of file class.ilGlobalCacheDBLayer.php.

278 {
279 $this->loaded = $loaded;
280 }

Referenced by __construct(), and readFromCache().

+ Here is the caller graph for this function:

◆ setRawData()

ilGlobalCacheDBLayer::setRawData (   $raw_data)
Parameters
array$raw_data

Definition at line 246 of file class.ilGlobalCacheDBLayer.php.

246 {
247 $this->raw_data = $raw_data;
248 }

Referenced by readFromCache().

+ Here is the caller graph for this function:

◆ setTableName()

ilGlobalCacheDBLayer::setTableName (   $table_name)
Parameters
string$table_name

Definition at line 262 of file class.ilGlobalCacheDBLayer.php.

262 {
263 $this->table_name = $table_name;
264 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setTtl()

ilGlobalCacheDBLayer::setTtl (   $ttl)
Parameters
int$ttl

Definition at line 310 of file class.ilGlobalCacheDBLayer.php.

310 {
311 $this->ttl = $ttl;
312 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ updateCachedResults()

ilGlobalCacheDBLayer::updateCachedResults ( )
protected

Definition at line 169 of file class.ilGlobalCacheDBLayer.php.

169 {
170 $this->global_cache->set($this->getTableName() . '_cached_results', $this->getCachedResults());
171 }

Referenced by writeToCache().

+ Here is the caller graph for this function:

◆ where()

ilGlobalCacheDBLayer::where (   $field,
  $value,
  $case_sensitive = true 
)
Parameters
$field
$value
bool$case_sensitive
Returns
$this

Definition at line 181 of file class.ilGlobalCacheDBLayer.php.

181 {
182 $ilGcDbWhere = new ilGcDbWhere();
183 $ilGcDbWhere->setField($field);
184 $ilGcDbWhere->setValue($value);
185 $ilGcDbWhere->setCaseSensitive($case_sensitive);
186 $this->wheres[] = $ilGcDbWhere;
187
188 return $this;
189 }

◆ writeToCache()

ilGlobalCacheDBLayer::writeToCache ( )
protected

Definition at line 82 of file class.ilGlobalCacheDBLayer.php.

82 {
83 if ($this->global_cache->isActive()) {
84 $this->global_cache->set($this->getTableName() . '_raw_data', $this->getRawData(), $this->getTtl());
85 $this->updateCachedResults();
86 }
87 }

References getRawData(), getTableName(), getTtl(), and updateCachedResults().

Referenced by __construct().

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

Field Documentation

◆ $cached_results

ilGlobalCacheDBLayer::$cached_results = array()
protected

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

Referenced by readFromCache().

◆ $component

ilGlobalCacheDBLayer::$component = ''
protected

Definition at line 15 of file class.ilGlobalCacheDBLayer.php.

Referenced by __construct().

◆ $global_cache

ilGlobalCacheDBLayer::$global_cache
protected

Definition at line 43 of file class.ilGlobalCacheDBLayer.php.

◆ $instances

ilGlobalCacheDBLayer::$instances = array()
staticprotected

Definition at line 27 of file class.ilGlobalCacheDBLayer.php.

◆ $loaded

ilGlobalCacheDBLayer::$loaded = false
protected

Definition at line 19 of file class.ilGlobalCacheDBLayer.php.

◆ $raw_data

ilGlobalCacheDBLayer::$raw_data = array()
protected

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

◆ $table_name

ilGlobalCacheDBLayer::$table_name = ''
protected

Definition at line 23 of file class.ilGlobalCacheDBLayer.php.

Referenced by __construct().

◆ $ttl

ilGlobalCacheDBLayer::$ttl = NULL
protected

Definition at line 39 of file class.ilGlobalCacheDBLayer.php.

Referenced by __construct().

◆ $wheres

ilGlobalCacheDBLayer::$wheres = array()
protected

Definition at line 47 of file class.ilGlobalCacheDBLayer.php.


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