Changeset 1138

Show
Ignore:
Timestamp:
12/11/07 15:57:23 (10 months ago)
Author:
mikey
Message:

bugfix: do not cache session stuff
(more kind of a hack, but did not come up with a better solution yet)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/cache/stubAbstractWebsiteCache.php

    r1112 r1138  
    4747     * 
    4848     * @param   stubRequest   $request 
     49     * @param   stubSession   $session 
    4950     * @param   stubResponse  $response 
    5051     * @param   string        $page      name of the page to be cached 
    5152     * @return  bool          true if data was retrieved from cache, else false 
    5253     */ 
    53     public function retrieve(stubRequest $request, stubResponse $response, $page) 
     54    public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 
    5455    { 
    5556        $cacheKey = $this->generateCacheKey($page); 
     
    6364        } 
    6465         
    65         if ($this->doRetrieve($request, $response, $cacheKey) === true) { 
     66        if ($this->doRetrieve($request, $session, $response, $cacheKey) === true) { 
    6667            $this->log($page, $cacheKey, stubWebsiteCache::HIT); 
    6768            return true; 
     
    7677     * 
    7778     * @param   stubRequest   $request 
     79     * @param   stubSession   $session 
    7880     * @param   stubResponse  $response 
    7981     * @param   string        $cacheKey 
    8082     * @return  bool          true if data was retrieved from cache, else false 
    8183     */ 
    82     protected abstract function doRetrieve(stubRequest $request, stubResponse $response, $cacheKey); 
     84    protected abstract function doRetrieve(stubRequest $request, stubSession $session, stubResponse $response, $cacheKey); 
    8385 
    8486    /** 
  • trunk/src/main/php/net/stubbles/websites/cache/stubDefaultWebsiteCache.php

    r1112 r1138  
    104104     * 
    105105     * @param   stubRequest   $request 
     106     * @param   stubSession   $session 
    106107     * @param   stubResponse  $response 
    107108     * @param   string        $cacheKey 
    108109     * @return  bool          true if successfully retrieved, else false 
    109110     */ 
    110     protected function doRetrieve(stubRequest $request, stubResponse $response, $cacheKey) 
     111    protected function doRetrieve(stubRequest $request, stubSession $session, stubResponse $response, $cacheKey) 
    111112    { 
    112         $response->write($this->cache->get($cacheKey)); 
     113        $contents = $this->cache->get($cacheKey); 
     114        $contents = str_replace('$SID', $session->getName() . '=' . $session->getId(), $contents); 
     115        $contents = str_replace('$SESSION_NAME', $session->getName(), $contents); 
     116        $contents = str_replace('$SESSION_ID', $session->getId(), $contents); 
     117        $response->write($contents); 
    113118        return true; 
    114119    } 
  • trunk/src/main/php/net/stubbles/websites/cache/stubGzipWebsiteCache.php

    r1130 r1138  
    113113     * 
    114114     * @param   stubRequest   $request 
     115     * @param   stubSession   $session 
    115116     * @param   stubResponse  $response 
    116117     * @param   string        $page      name of the page to be cached 
    117118     * @return  bool          true if data was retrieved from cache, else false 
    118119     */ 
    119     public function retrieve(stubRequest $request, stubResponse $response, $page) 
    120     { 
    121         if (parent::retrieve($request, $response, $page) === true) { 
     120    public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 
     121    { 
     122        if (parent::retrieve($request, $session, $response, $page) === true) { 
    122123            return true; 
    123124        } 
    124125         
    125         return $this->websiteCache->retrieve($request, $response, $page); 
     126        return $this->websiteCache->retrieve($request, $session, $response, $page); 
    126127    } 
    127128 
     
    130131     * 
    131132     * @param   stubRequest   $request 
     133     * @param   stubSession   $session 
    132134     * @param   stubResponse  $response 
    133135     * @param   string        $cacheKey 
    134136     * @return  bool          true if data was retrieved from cache, else false 
    135137     */ 
    136     protected function doRetrieve(stubRequest $request, stubResponse $response, $cacheKey) 
     138    protected function doRetrieve(stubRequest $request, stubSession $session, stubResponse $response, $cacheKey) 
    137139    { 
    138140        // we do not use gzipped content because we probably have to insert 
     
    199201    { 
    200202        $data  = $response->getData(); 
     203        $data  = str_replace('$SID', '', $data); 
     204        $data  = str_replace('$SESSION_NAME', '', $data); 
     205        $data  = str_replace('$SESSION_ID', '', $data); 
    201206        $size  = strlen($data); 
    202207        $crc32 = crc32($data); 
  • trunk/src/main/php/net/stubbles/websites/cache/stubWebsiteCache.php

    r1109 r1138  
    7474     * 
    7575     * @param   stubRequest   $request 
     76     * @param   stubSession   $session 
    7677     * @param   stubResponse  $response 
    7778     * @param   string        $page      name of the page to be cached 
    7879     * @return  bool          true if data was retrieved from cache, else false 
    7980     */ 
    80     public function retrieve(stubRequest $request, stubResponse $response, $page); 
     81    public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page); 
    8182 
    8283    /** 
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php

    r1137 r1138  
    110110        if (null !== $this->cache) { 
    111111            $this->processCacheVars($prefixRequest, $elements, $pageName, $frameId, $context); 
    112             if ($this->cache->retrieve($this->request, $this->response, $pageName) === true) { 
     112            if ($this->cache->retrieve($this->request, $this->session, $this->response, $pageName) === true) { 
    113113                return; 
    114114            } 
     
    122122        if (null !== $this->cache) { 
    123123            $this->cache->store($this->request, $this->response, $pageName); 
     124            $contents = str_replace('$SID', $this->session->getName() . '=' . $this->session->getId(), $this->response->getData()); 
     125            $contents = str_replace('$SESSION_NAME', $this->session->getName(), $contents); 
     126            $this->response->replaceData(str_replace('$SESSION_ID', $this->session->getId(), $contents)); 
    124127        } 
    125128    } 
     
    283286        $this->template->addGlobalVar('PAGE_NAME', $pageName); 
    284287        $this->template->addGlobalVar('VARIANT', $this->session->getValue('net.stubbles.websites.variantmanager.variant', '')); 
    285         $this->template->addGlobalVar('SID', $this->session->getName() . '=' . $this->session->getId()); 
    286         $this->template->addGlobalVar('SESSION_NAME', $this->session->getName()); 
    287         $this->template->addGlobalVar('SESSION_ID', $this->session->getId()); 
     288        if (null === $this->cache) { 
     289            $this->template->addGlobalVar('SID', $this->session->getName() . '=' . $this->session->getId()); 
     290            $this->template->addGlobalVar('SESSION_NAME', $this->session->getName()); 
     291            $this->template->addGlobalVar('SESSION_ID', $this->session->getId()); 
     292        } else { 
     293            $this->template->addGlobalVar('SID', '$SID'); 
     294            $this->template->addGlobalVar('SESSION_NAME', '$SESSION_NAME'); 
     295            $this->template->addGlobalVar('SESSION_ID', '$SESSION_ID'); 
     296        } 
    288297         
    289298        // check for user data 
  • trunk/src/test/php/net/stubbles/websites/cache/stubAbstractWebsiteCacheTestCase.php

    r1123 r1138  
    2424); 
    2525Mock::generate('stubRequest'); 
     26Mock::generate('stubSession'); 
    2627Mock::generate('stubResponse'); 
    2728Mock::generate('stubCacheContainer'); 
     
    8182    protected $mockRequest; 
    8283    /** 
     84     * mocked session instance 
     85     * 
     86     * @var  SimpleMock 
     87     */ 
     88    protected $mockSession; 
     89    /** 
    8390     * mocked response instance 
    8491     * 
     
    97104        $this->abstractWebsiteCache->setReturnValue('getCacheVars', array('foo' => 'bar')); 
    98105        $this->mockRequest  = new MockstubRequest(); 
     106        $this->mockSession  = new MockstubSession(); 
    99107        $this->mockResponse = new MockstubResponse(); 
    100108    } 
     
    111119        $this->mockResponse->expectNever('addHeader'); 
    112120        $this->mockCacheContainer->expectNever('has'); 
    113         $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'baz')); 
     121        $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 
    114122        $this->assertEqual($this->abstractWebsiteCache->getMissReason(), 'disabled'); 
    115123        stubMode::setCurrent($currentMode); 
     
    126134        $this->mockCacheContainer->expectOnce('has'); 
    127135        $this->mockCacheContainer->setReturnValue('has', false); 
    128         $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'baz')); 
     136        $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 
    129137        $this->assertEqual($this->abstractWebsiteCache->getMissReason(), 'no cache file'); 
    130138    } 
     
    136144    { 
    137145        $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::MISS)); 
    138         $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockResponse, '*')); 
     146        $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 
    139147        $this->abstractWebsiteCache->setReturnValue('doRetrieve', false); 
    140148        $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); 
     
    143151        $this->mockCacheContainer->expectOnce('has'); 
    144152        $this->mockCacheContainer->setReturnValue('has', true); 
    145         $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'baz')); 
     153        $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 
    146154        $this->assertEqual($this->abstractWebsiteCache->getMissReason(), ''); 
    147155    } 
     
    153161    { 
    154162        $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::HIT)); 
    155         $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockResponse, '*')); 
     163        $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 
    156164        $this->abstractWebsiteCache->setReturnValue('doRetrieve', true); 
    157165        $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); 
     
    160168        $this->mockCacheContainer->expectOnce('has'); 
    161169        $this->mockCacheContainer->setReturnValue('has', true); 
    162         $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'baz')); 
     170        $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 
    163171        $this->assertEqual($this->abstractWebsiteCache->getMissReason(), ''); 
    164172    } 
     
    172180        stubMode::setCurrent(stubMode::$TEST); 
    173181        $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::HIT)); 
    174         $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockResponse, '*')); 
     182        $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 
    175183        $this->abstractWebsiteCache->setReturnValue('doRetrieve', true); 
    176184        $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); 
     
    179187        $this->mockCacheContainer->expectOnce('has'); 
    180188        $this->mockCacheContainer->setReturnValue('has', true); 
    181         $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'baz')); 
     189        $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 
    182190        $this->assertEqual($this->abstractWebsiteCache->getMissReason(), ''); 
    183191        stubMode::setCurrent($currentMode); 
  • trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheTestCase.php

    r1129 r1138  
    99stubClassLoader::load('net.stubbles.websites.cache.stubDefaultWebsiteCache'); 
    1010Mock::generate('stubRequest'); 
     11Mock::generate('stubSession'); 
    1112Mock::generate('stubResponse'); 
    1213Mock::generate('stubCacheContainer'); 
     
    2425     * 
    2526     * @param   stubRequest   $request 
     27     * @param   stubSession   $session 
    2628     * @param   stubResponse  $response 
    2729     * @param   string        $page      name of the page to be cached 
    2830     * @return  bool          true if data was retrieved from cache, else false 
    2931     */ 
    30     public function retrieve(stubRequest $request, stubResponse $response, $page) 
    31     { 
    32         return $this->doRetrieve($request, $response, $page); 
     32    public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 
     33    { 
     34        return $this->doRetrieve($request, $session, $response, $page); 
    3335    } 
    3436 
     
    103105    protected $mockRequest; 
    104106    /** 
     107     * mocked session instance 
     108     * 
     109     * @var  SimpleMock 
     110     */ 
     111    protected $mockSession; 
     112    /** 
    105113     * mocked response instance 
    106114     * 
     
    117125        $this->defaultWebsiteCache = new TeststubDefaultWebsiteCache($this->mockCacheContainer); 
    118126        $this->mockRequest         = new MockstubRequest(); 
     127        $this->mockSession         = new MockstubSession(); 
    119128        $this->mockResponse        = new MockstubResponse(); 
    120129    } 
     
    176185        $this->mockCacheContainer->setReturnValue('get', 'fooContents'); 
    177186        $this->mockResponse->expectOnce('write', array('fooContents')); 
    178         $this->assertTrue($this->defaultWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'foo')); 
     187        $this->assertTrue($this->defaultWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    179188    } 
    180189 
  • trunk/src/test/php/net/stubbles/websites/cache/stubGzipWebsiteCacheTestCase.php

    r1130 r1138  
    99stubClassLoader::load('net.stubbles.websites.cache.stubGzipWebsiteCache'); 
    1010Mock::generate('stubRequest'); 
     11Mock::generate('stubSession'); 
    1112Mock::generate('stubResponse'); 
    1213Mock::generate('stubCacheContainer'); 
     
    2526     * 
    2627     * @param   stubRequest   $request 
     28     * @param   stubSession   $session 
    2729     * @param   stubResponse  $response 
    2830     * @param   string        $page      name of the page to be cached 
    2931     * @return  bool          true if data was retrieved from cache, else false 
    3032     */ 
    31     public function retrieve(stubRequest $request, stubResponse $response, $page) 
    32     { 
    33         return $this->doRetrieve($request, $response, $page); 
     33    public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 
     34    { 
     35        return $this->doRetrieve($request, $session, $response, $page); 
    3436    } 
    3537 
     
    8890    protected $mockRequest; 
    8991    /** 
     92     * mocked session instance 
     93     * 
     94     * @var  SimpleMock 
     95     */ 
     96    protected $mockSession; 
     97    /** 
    9098     * mocked response instance 
    9199     * 
     
    104112        $this->gzipWebsiteCache = new TeststubGzipWebsiteCache($this->mockWebsiteCache); 
    105113        $this->mockRequest      = new MockstubRequest(); 
     114        $this->mockSession      = new MockstubSession(); 
    106115        $this->mockResponse     = new MockstubResponse(); 
    107116    } 
     
    154163        $this->mockResponse->expectNever('addHeader'); 
    155164        $this->mockResponse->expectNever('write'); 
    156         $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'foo')); 
     165        $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    157166        $this->assertEqual($this->gzipWebsiteCache->getMissReason(), 'user agent does not accept cookies'); 
    158167    } 
     
    167176        $this->mockResponse->expectNever('addHeader'); 
    168177        $this->mockResponse->expectNever('write'); 
    169         $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'foo')); 
     178        $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    170179        $this->assertEqual($this->gzipWebsiteCache->getMissReason(), 'user agent does not accept compressed content'); 
    171180    } 
     
    183192        $this->mockResponse->expectAt(1, 'write', array('cachedContents')); 
    184193        $this->mockCacheContainer->setReturnValue('get', 'cachedContents'); 
    185         $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'foo')); 
     194        $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    186195        $this->assertEqual($this->gzipWebsiteCache->getMissReason(), ''); 
    187196    } 
     
    200209        $this->mockResponse->expectAt(1, 'write', array('cachedContents')); 
    201210        $this->mockCacheContainer->setReturnValue('get', 'cachedContents'); 
    202         $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockResponse, 'foo')); 
     211        $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    203212        $this->assertEqual($this->gzipWebsiteCache->getMissReason(), ''); 
    204213    } 
     
    209218    public function testStore() 
    210219    { 
    211         $this->mockResponse->setReturnValue('getData', 'fooContent'); 
     220        $this->mockResponse->setReturnValue('getData', 'fooContent$SIDbla$SESSION_NAMEblub$SESSION_ID'); 
    212221        $this->mockWebsiteCache->expectOnce('store', array($this->mockRequest, $this->mockResponse, 'foo')); 
    213222        $this->mockWebsiteCache->setReturnValue('store', true); 
  • trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php

    r1137 r1138  
    332332        $memphisProcessor->expectOnce('setTemplateVars', array('*', 'foo', 'bar')); 
    333333        $memphisProcessor->expectOnce('processPageElements', array('*', array('baz' => $mockPageElement), '*')); 
     334        $this->mockResponse->expectNever('getData'); 
     335        $this->mockResponse->expectNever('replaceData'); 
    334336        $memphisProcessor->callDoProcess(); 
    335337    } 
     
    355357        $memphisProcessor->expectOnce('processPageElements', array('*', array('baz' => $mockPageElement), '*')); 
    356358        $mockCache = new MockstubWebsiteCache(); 
    357         $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mockResponse, 'foo')); 
     359        $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    358360        $mockCache->setReturnValue('retrieve', false); 
    359361        $mockCache->expectOnce('store', array($this->mockRequest, $this->mockResponse, 'foo')); 
    360362        $memphisProcessor->setWebsiteCache($mockCache); 
     363        $this->mockResponse->expectOnce('getData'); 
     364        $this->mockResponse->setReturnValue('getData', '$SID$SESSION_NAME$SESSION_ID'); 
     365        $this->mockSession->setReturnValue('getId', 'id'); 
     366        $this->mockSession->setReturnValue('getName', 'name'); 
     367        $this->mockResponse->expectOnce('replaceData', array('name=idnameid')); 
    361368        $memphisProcessor->callDoProcess(); 
    362369    } 
     
    381388        $memphisProcessor->expectNever('processPageElements'); 
    382389        $mockCache = new MockstubWebsiteCache(); 
    383         $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mockResponse, 'foo')); 
     390        $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 
    384391        $mockCache->setReturnValue('retrieve', true); 
    385392        $mockCache->expectNever('store'); 
    386393        $memphisProcessor->setWebsiteCache($mockCache); 
     394        $this->mockResponse->expectNever('getData'); 
     395        $this->mockResponse->expectNever('replaceData'); 
    387396        $memphisProcessor->callDoProcess(); 
    388397    } 
     
    706715    public function testSetTemplateVars2() 
    707716    { 
     717        $mockCache = new MockstubWebsiteCache(); 
     718        $this->memphisProcessor->setWebsiteCache($mockCache); 
    708719        $this->mockMemphisConfig->setReturnValue('getMetaTags', array()); 
    709720        $this->mockMemphisTemplate->expectAt(0, 'addGlobalVar', array('UCUO_FRAME', 'foo')); 
     
    711722        $this->mockMemphisTemplate->expectAt(2, 'addGlobalVar', array('PAGE_NAME', 'baz')); 
    712723        $this->mockMemphisTemplate->expectAt(3, 'addGlobalVar', array('VARIANT', 'variant')); 
    713         $this->mockMemphisTemplate->expectAt(4, 'addGlobalVar', array('SID', 'sessionid=313')); 
    714         $this->mockMemphisTemplate->expectAt(5, 'addGlobalVar', array('SESSION_NAME', 'sessionid')); 
    715         $this->mockMemphisTemplate->expectAt(6, 'addGlobalVar', array('SESSION_ID', 313)); 
     724        $this->mockMemphisTemplate->expectAt(4, 'addGlobalVar', array('SID', '$SID')); 
     725        $this->mockMemphisTemplate->expectAt(5, 'addGlobalVar', array('SESSION_NAME', '$SESSION_NAME')); 
     726        $this->mockMemphisTemplate->expectAt(6, 'addGlobalVar', array('SESSION_ID', '$SESSION_ID')); 
    716727        $this->mockMemphisTemplate->expectAt(7, 'addGlobalVar', array('SSL_MODE', 'yes')); 
    717728        $this->mockMemphisTemplate->expectNever('addVar');