function getComponentsHookCache() { if (!isset($GLOBALS['_MAX']['ComponentHooks'])) { $oCache = new OA_Cache('Plugins', 'ComponentHooks'); $oCache->setFileNameProtection(false); $GLOBALS['_MAX']['ComponentHooks'] = $oCache->load(true); if ($GLOBALS['_MAX']['ComponentHooks'] === false) { require_once LIB_PATH . '/Plugin/PluginManager.php'; $oPluginManager = new OX_PluginManager(); $GLOBALS['_MAX']['ComponentHooks'] = $oPluginManager->getComponentHooks(); $oCache->save($GLOBALS['_MAX']['ComponentHooks']); } } return $GLOBALS['_MAX']['ComponentHooks']; }
function _saveToCache($accountType) { $oCache = new OA_Cache('Menu', $accountType); $oCache->setFileNameProtection(false); return $oCache->save(array('checkerPaths' => $this->aCheckerIncludePaths, 'oMenu' => serialize($this))); }
/** * perform post-audit actions * * @param int $actionid * @param DataObjects_Campaigns $dataobjectOld * @param int $auditId */ function _postAuditTrigger($actionid, $dataobjectOld, $auditId) { $aActionMap = array(); $aActionMap[OA_ENTITY_STATUS_RUNNING][OA_ENTITY_STATUS_AWAITING] = 'started'; $aActionMap[OA_ENTITY_STATUS_RUNNING][''] = 'restarted'; $aActionMap[OA_ENTITY_STATUS_EXPIRED][''] = 'completed'; $aActionMap[OA_ENTITY_STATUS_PAUSED][''] = 'paused'; $aActionMap[OA_ENTITY_STATUS_AWAITING][''] = 'paused'; switch ($actionid) { case OA_AUDIT_ACTION_INSERT: $actionType = 'added'; case OA_AUDIT_ACTION_UPDATE: if (isset($this->status) && $this->status != $dataobjectOld->status) { if (isset($aActionMap[$this->status][$dataobjectOld->status])) { $actionType = $aActionMap[$this->status][$dataobjectOld->status]; } elseif (isset($aActionMap[$this->status][''])) { $actionType = $aActionMap[$this->status]['']; } } break; case OA_AUDIT_ACTION_DELETE: $actionType = 'deleted'; break; } if (isset($actionType)) { // Prepare action array $maxItems = 6; $aAction = array('campaignid' => $this->campaignid, 'name' => $this->campaignname, 'clientid' => $this->clientid, 'auditid' => $auditId, 'action' => $actionType); // Load cache require_once MAX_PATH . '/lib/OA/Cache.php'; $oCache = new OA_Cache('campaignOverview', 'Widgets'); $aCache = $oCache->load(true); if (!$aCache) { // No cache, initialise $aCache = array('maxItems' => $maxItems, 'aAccounts' => array()); } // Get owning account id $accountId = $this->doAudit->account_id; if (!isset($aCache['aAccounts'][$accountId])) { // No cached array for this account id, initialise $aCache['aAccounts'][$accountId] = array(); } // Add current action as first item array_unshift($aCache['aAccounts'][$accountId], $aAction); //if current campaign is deleted, delete campaignid in all messages concernig this campaign if ($actionType == 'deleted') { //var_dump($aCache['aAccounts'][$accountId]); foreach ($aCache['aAccounts'][$accountId] as $k => $v) { if ($v['campaignid'] == $aAction['campaignid']) { $aCache['aAccounts'][$accountId][$k]['campaignid'] = ""; } } } // Only store most recent $maxItems actions, rekeying the array $aCache['aAccounts'][$accountId] = array_slice($aCache['aAccounts'][$accountId], 0, $maxItems); // Save cache $oCache->save($aCache); } }
function testLifeTime() { $oCache = new OA_Cache('test', 'oxpTestCache', 1); $oCache->setFileNameProtection(false); $oCache->clear(); // File not exist $result = $oCache->load(false); $this->assertFalse($result); $data = 'test'; $oCache->save($data); // File exists $result = $oCache->load(false); $this->assertEqual($result, $data); // Wait 3 seconds and set cache lifetime to 1 second sleep(3); $oCache = new OA_Cache('test', 'oxpTestCache', 1); $oCache->setFileNameProtection(false); // File exists but is not valid $result = $oCache->load(false); $this->assertFalse($result); // Try to retrive cache ignoring lifetime $result = $oCache->load(true); $this->assertEqual($result, $data); }