/**
  * Method tests invalidateAll method
  *
  */
 function test_invalidateAll()
 {
     for ($i = 0; $i < 5; $i++) {
         $filename = 'testname' . $i;
         OA_Delivery_Cache_store($filename, $i);
     }
     for ($i = 0; $i < 5; $i++) {
         $this->assertEqual($i, OA_Delivery_Cache_fetch('testname' . $i));
     }
     $result = $this->oDeliveryCacheCommon->invalidateAll();
     $this->assertTrue($result);
     for ($i = 0; $i < 5; $i++) {
         $this->assertFalse(OA_Delivery_Cache_fetch('testname' . $i));
     }
 }
Ejemplo n.º 2
0
function MAX_cacheCheckIfMaintenanceShouldRun($cached = true)
{
    $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60;
    $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60);
    $now = MAX_commonGetTimeNow();
    $today = strtotime(date('Y-m-d'), $now);
    $nextRunTime = $today + (floor(($now - $today) / $interval) + 1) * $interval + $delay;
    if ($nextRunTime - $now > $interval) {
        $nextRunTime -= $interval;
    }
    $cName = OA_Delivery_Cache_getName(__FUNCTION__);
    if (!$cached || ($lastRunTime = OA_Delivery_Cache_fetch($cName)) === false) {
        MAX_Dal_Delivery_Include();
        $lastRunTime = OA_Dal_Delivery_getMaintenanceInfo();
        if ($lastRunTime >= $nextRunTime - $delay) {
            $nextRunTime += $interval;
        }
        OA_Delivery_Cache_store($cName, $lastRunTime, false, $nextRunTime);
    }
    return $lastRunTime < $nextRunTime - $interval;
}
Ejemplo n.º 3
0
/**
 * Check if maintenance should run using cached information
 *
 * This function gets maintenance's last run info
 *
 * @param boolean $cached   Should a cache lookup be performed?
 * @return array            The array of tracker properties
 */
function MAX_cacheCheckIfMaintenanceShouldRun($cached = true)
{
    // Default delay is 5 minutes
    $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60;
    $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60);
    $now = MAX_commonGetTimeNow();
    $today = strtotime(date('Y-m-d'), $now);
    $nextRunTime = $today + (floor(($now - $today) / $interval) + 1) * $interval + $delay;
    // Adding the delay could shift the time to the next operation interval,
    // make sure to fix it in case it happens
    if ($nextRunTime - $now > $interval) {
        $nextRunTime -= $interval;
    }
    $cName = OA_Delivery_Cache_getName(__FUNCTION__);
    if (!$cached || ($lastRunTime = OA_Delivery_Cache_fetch($cName)) === false) {
        MAX_Dal_Delivery_Include();
        $lastRunTime = OA_Dal_Delivery_getMaintenanceInfo();
        // Cache until the next operation interval if scheduled maintenance was run
        // during the delay
        if ($lastRunTime >= $nextRunTime - $delay) {
            $nextRunTime += $interval;
        }
        OA_Delivery_Cache_store($cName, $lastRunTime, false, $nextRunTime);
    }
    return $lastRunTime < $nextRunTime - $interval;
}