Changeset 2169

Show
Ignore:
Timestamp:
11/02/07 14:11:47 (14 months ago)
Author:
david
Message:

more graceful handling of potential race conditions on cache read, closes #608

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/src/filter/AgaviExecutionFilter.class.php

    r2117 r2169  
    8888      $group = base64_encode($group); 
    8989    } 
    90     return unserialize(file_get_contents(AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_SUBDIR . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $groups) . '.cefcache')); 
     90    $filename = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_SUBDIR . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $groups) . '.cefcache'; 
     91    $data = file_get_contents($filename); 
     92    if($data !== false) { 
     93      return unserialize($data); 
     94    } else { 
     95      throw new AgaviException(sprintf('Failed to read cache file "%s"', $filename)); 
     96    } 
    9197  } 
    9298 
     
    272278      // $lm->log('Action is cached, loading...'); 
    273279      // cache/dir/4-8-15-16-23-42 contains the action cache 
    274       $actionCache = $this->readCache(array_merge($groups, array(self::ACTION_CACHE_ID))); 
    275     } else { 
     280      try { 
     281        $actionCache = $this->readCache(array_merge($groups, array(self::ACTION_CACHE_ID))); 
     282      } catch(AgaviException $e) { 
     283        $isActionCached = false; 
     284      } 
     285    } 
     286    if(!$isActionCached) { 
     287      $actionCache = array(); 
     288       
    276289      // $lm->log('Action not cached, executing...'); 
    277290      // execute the Action and get the View to execute 
     
    331344      if($isViewCached) { 
    332345        // $lm->log('View is cached, loading...'); 
    333         $viewCache = $this->readCache(array_merge($groups, array($outputType))); 
    334       } else { 
     346        try { 
     347          $viewCache = $this->readCache(array_merge($groups, array($outputType))); 
     348        } catch(AgaviException $e) { 
     349          $isViewCached = false; 
     350        } 
     351      } 
     352      if(!$isViewCached) { 
    335353        $viewCache = array(); 
    336354