Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ZurmoCache.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
44  abstract class ZurmoCache
45  {
46  const ALLOW_PHP_CACHING = true;
47 
48  const ALLOW_MEMCACHE_CACHING = true;
49 
50  const ALLOW_DB_CACHING = true;
51 
52  const CACHE_VALUE_KEY = 'value';
53 
54  const CACHE_CHECKSUM_KEY = 'checksum';
55 
56  public static $cacheType = 'Z:';
57 
58  protected static $cacheIncrementValueVariableName = 'CacheIncrementValue';
59 
60  protected static $additionalStringForCachePrefix = '';
61 
68  public static function getCachePrefix($identifier)
69  {
70  if (static::isIdentifierCacheIncrementValueName($identifier))
71  {
72  $prefix = ZURMO_TOKEN . '_' . static::$cacheType;
73  }
74  else
75  {
76  $cacheIncrementValue = static::getCacheIncrementValue(static::$cacheType);
77  $prefix = ZURMO_TOKEN . '_' . $cacheIncrementValue . '_' . static::$cacheType;
78  }
79 
80  if (static::getAdditionalStringForCachePrefix() != '')
81  {
82  $prefix = static::getAdditionalStringForCachePrefix() . '_' . $prefix;
83  }
84 
85  return $prefix;
86  }
87 
98  protected static function getCacheIncrementValue($cacheType)
99  {
100  try
101  {
102  $cacheIncrementValue = GeneralCache::getEntry(static::$cacheIncrementValueVariableName . $cacheType);
103  }
104  catch (NotFoundException $e)
105  {
106  $cacheIncrementValue = 0;
107  static::setCacheIncrementValue($cacheType, $cacheIncrementValue);
108  }
109  return $cacheIncrementValue;
110  }
111 
116  protected static function setCacheIncrementValue($cacheType, $value)
117  {
118  GeneralCache::cacheEntry(static::$cacheIncrementValueVariableName . $cacheType, $value);
119  }
120 
125  protected static function incrementCacheIncrementValue($cacheType)
126  {
127  $currentCacheIncrementValue = static::getCacheIncrementValue($cacheType);
128  $currentCacheIncrementValue++;
129  static::setCacheIncrementValue($cacheType, $currentCacheIncrementValue);
130  }
131 
137  protected static function isIdentifierCacheIncrementValueName($identifier)
138  {
139  if (strstr($identifier, static::$cacheIncrementValueVariableName) !== false)
140  {
141  return true;
142  }
143  else
144  {
145  return false;
146  }
147  }
148 
156  public static function setAdditionalStringForCachePrefix($prefix = '')
157  {
158  static::$additionalStringForCachePrefix = $prefix;
159  }
160 
165  public static function getAdditionalStringForCachePrefix()
166  {
167  return static::$additionalStringForCachePrefix;
168  }
169 
173  public static function supportsAndAllowsMemcache()
174  {
175  return (static::ALLOW_MEMCACHE_CACHING && MEMCACHE_ON && Yii::app()->cache !== null);
176  }
177 
181  public static function supportsAndAllowsPhpCaching()
182  {
183  return (static::ALLOW_PHP_CACHING && PHP_CACHING_ON);
184  }
185 
189  public static function supportsAndAllowsDatabaseCaching()
190  {
191  return (static::ALLOW_DB_CACHING && DB_CACHING_ON);
192  }
193 
197  protected static function clearMemcacheCache()
198  {
199  if (static::supportsAndAllowsMemcache())
200  {
201  if (ArrayUtil::getArrayValue(Yii::app()->params, 'hasDedicatedMemcachePool'))
202  {
203  @Yii::app()->cache->flush();
204  }
205  else
206  {
207  static::incrementCacheIncrementValue(static::$cacheType);
208  }
209  }
210  }
211 
212  protected static function cacheValueAndChecksum($key, $value)
213  {
214  $checksum = crc32(serialize($value));
215  $cachedData = array(static::CACHE_VALUE_KEY => $value, static::CACHE_CHECKSUM_KEY => $checksum);
216  return Yii::app()->cache->set($key, $cachedData);
217  }
218 
219  protected static function getCachedValueAndValidateChecksum($key)
220  {
221  $cachedData = Yii::app()->cache->get($key);
222  if ($cachedData === false)
223  {
224  return false;
225  }
226  if (!is_array($cachedData) || !array_key_exists(static::CACHE_VALUE_KEY, $cachedData) || !array_key_exists(static::CACHE_CHECKSUM_KEY, $cachedData))
227  {
228  return false;
229  }
230  $data = $cachedData[static::CACHE_VALUE_KEY];
231  $checksum = $cachedData[static::CACHE_CHECKSUM_KEY];
232  assert('$checksum == crc32(serialize($data))');
233  if (YII_DEBUG)
234  {
235  if (crc32(serialize($data)) != $checksum)
236  {
237  throw new ChecksumMismatchException();
238  }
239  }
240  if ($checksum != crc32(serialize($data)))
241  {
242  return false;
243  }
244  return $data;
245  }
246  }
247 ?>
static setAdditionalStringForCachePrefix($prefix= '')
Definition: ZurmoCache.php:156
static supportsAndAllowsPhpCaching()
Definition: ZurmoCache.php:181
static supportsAndAllowsDatabaseCaching()
Definition: ZurmoCache.php:189
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static getAdditionalStringForCachePrefix()
Definition: ZurmoCache.php:165
static clearMemcacheCache()
Definition: ZurmoCache.php:197
static supportsAndAllowsMemcache()
Definition: ZurmoCache.php:173
static isIdentifierCacheIncrementValueName($identifier)
Definition: ZurmoCache.php:137
static setCacheIncrementValue($cacheType, $value)
Definition: ZurmoCache.php:116
static getCacheIncrementValue($cacheType)
Definition: ZurmoCache.php:98
static incrementCacheIncrementValue($cacheType)
Definition: ZurmoCache.php:125
static getCachePrefix($identifier)
Definition: ZurmoCache.php:68
Generated on Mon Jul 6 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.