Skip to content

Commit

Permalink
[#3111] Fix bug causing resource cache files to be over-written unnec…
Browse files Browse the repository at this point in the history
…essarily
  • Loading branch information
opengeek committed Feb 20, 2011
1 parent 5c2e5de commit 82ad456
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/docs/changelog.txt
Expand Up @@ -4,6 +4,7 @@ development release, and is only shown to give an idea of what's currently in th

MODx Revolution 2.0.8-pl (February 21, 2011)
====================================
- [#3111] Fix bug causing resource cache files to be over-written unnecessarily

MODx Revolution 2.0.7-pl (January 14, 2011)
====================================
Expand Down
5 changes: 3 additions & 2 deletions core/model/modx/modrequest.class.php
Expand Up @@ -147,7 +147,8 @@ public function getResource($method, $identifier) {
}
$fromCache = false;
$cacheKey = $this->modx->context->get('key') . "/resources/{$resourceId}";
if ($cachedResource = $this->modx->cacheManager->get($cacheKey)) {
$cachedResource = $this->modx->cacheManager->get($cacheKey);
if (is_array($cachedResource) && array_key_exists('resource', $cachedResource) && is_array($cachedResource['resource'])) {
$resource = $this->modx->newObject($cachedResource['resourceClass']);
if ($resource) {
$resource->fromArray($cachedResource['resource'], '', true, true, true);
Expand All @@ -172,7 +173,6 @@ public function getResource($method, $identifier) {
$fromCache = true;
}
}
$this->modx->resourceGenerated = (boolean) !$fromCache;
if (!$fromCache || !is_object($resource)) {
$criteria = array('id' => $resourceId, 'deleted' => '0');
if (!$this->modx->hasPermission('view_unpublished')) $criteria['published']= 1;
Expand All @@ -198,6 +198,7 @@ public function getResource($method, $identifier) {
);
}
}
$this->modx->resourceGenerated = true;
}
}
} elseif ($fromCache && $resource instanceof modResource && !$resource->get('deleted')) {
Expand Down
4 changes: 2 additions & 2 deletions core/model/modx/modx.class.php
Expand Up @@ -157,7 +157,7 @@ class modX extends xPDO {
/**
* @var boolean Indicates if the resource was generated during this request.
*/
public $resourceGenerated= true;
public $resourceGenerated= false;
/**
* @var array Version information for this MODx deployment.
*/
Expand Down Expand Up @@ -2955,7 +2955,7 @@ protected function _logInRegister($register, $level, $msg, $def, $file, $line) {
* @access protected
*/
public function _postProcess() {
if ($this->getOption('cache_resource', true)) {
if ($this->resourceGenerated && $this->getOption('cache_resource', null, true)) {
if (is_object($this->resource) && $this->resource instanceof modResource && $this->resource->get('id') && $this->resource->get('cacheable')) {
$this->invokeEvent('OnBeforeSaveWebPageCache');
$this->cacheManager->generateResource($this->resource);
Expand Down

0 comments on commit 82ad456

Please sign in to comment.