ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilGlobalCacheQueryWrapper.php
Go to the documentation of this file.
1<?php
2require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
3
11
14 const MODE_SINGLE = 1;
15 const MODE_MULTIPLE = 2;
19 protected $query = '';
23 protected $cache_key = '';
32
33
40 public function __construct($cache_key, $query, $fetch_type = self::FETCH_TYPE_OBJECT, $mode = self::MODE_SINGLE) {
41 $this->cache_key = $cache_key;
42 $this->fetch_type = $fetch_type;
43 $this->mode = $mode;
44 $this->query = $query;
45 }
46
47
51 public function get() {
52 $ilGlobalCache = ilGlobalCache::getInstance();
53 if ($ilGlobalCache->isActive()) {
54 $rec = $ilGlobalCache->get($this->cache_key);
55 if (! $rec) {
56 $rec = $this->getFromDb();
57 $ilGlobalCache->set($this->cache_key, $rec, 600);
58 }
59 } else {
60 $rec = $this->getFromDb();
61 }
62
63 return $rec;
64 }
65
66
70 protected function getFromDb() {
71 global $ilDB;
75 $return = array();
76 $res = $ilDB->query($this->query);
77 switch ($this->getFetchType()) {
79 while ($rec = $ilDB->fetchObject($res)) {
80 $return[] = $rec;
81 }
82 break;
84 while ($rec = $ilDB->fetchAssoc($res)) {
85 $return[] = $rec;
86 }
87 break;
88 }
89
90 if ($this->getMode() == self::MODE_SINGLE) {
91 return $return[0];
92 } else {
93 return $return;
94 }
95 }
96
97
101 public function setFetchType($fetch_type) {
102 $this->fetch_type = $fetch_type;
103 }
104
105
109 public function getFetchType() {
110 return $this->fetch_type;
111 }
112
113
117 public function setMode($mode) {
118 $this->mode = $mode;
119 }
120
121
125 public function getMode() {
126 return $this->mode;
127 }
128}
129
130?>
Class ilGlobalCacheQueryWrapper.
__construct($cache_key, $query, $fetch_type=self::FETCH_TYPE_OBJECT, $mode=self::MODE_SINGLE)
static getInstance($component)
global $ilDB