I tried to make the Gallery extra work in MODX3, but encountered some issues with the cache.
In MODX 2.x these lines
clear the whole directories (core/cache/default/gallery/album/list
, etc.), but in MODX3 they don’t.
The problem seems to be, that the default value for “multiple_object_delete” has changed.
In 2.x the default value (third parameter) is true
.
if (file_exists($this->getCacheKey($key, $options))) {
if ($expire === true)
$expire= 0;
$replaced= $this->set($key, $var, $expire, $options);
}
return $replaced;
}
public function delete($key, $options= array()) {
$deleted= false;
if ($this->getOption('multiple_object_delete', $options, true)) {
$cacheKey= $this->getCacheKey($key, array_merge($options, array('cache_ext' => '')));
if (file_exists($cacheKey) && is_dir($cacheKey)) {
$results = $this->xpdo->cacheManager->deleteTree($cacheKey, array_merge(array('deleteTop' => false, 'skipDirs' => false, 'extensions' => array('.cache.php')), $options));
if ($results !== false) {
$deleted = true;
}
}
}
$cacheKey= $this->getCacheKey($key, $options);
if (file_exists($cacheKey)) {
In 3.x the default is false
.
if (file_exists($this->getCacheKey($key, $options))) {
if ($expire === true)
$expire= 0;
$replaced= $this->set($key, $var, $expire, $options);
}
return $replaced;
}
public function delete($key, $options= array()) {
$deleted= false;
if ($this->getOption(xPDO::OPT_CACHE_MULTIPLE_OBJECT_DELETE, $options, false)) {
$cacheKey= $this->getCacheKey($key, array_merge($options, array('cache_ext' => '')));
if (file_exists($cacheKey) && is_dir($cacheKey)) {
$results = $this->xpdo->cacheManager->deleteTree($cacheKey, array_merge(array('deleteTop' => false, 'skipDirs' => false, 'extensions' => array('.cache.php')), $options));
if ($results !== false) {
$deleted = true;
}
}
}
$cacheKey= $this->getCacheKey($key, $options);
if (file_exists($cacheKey)) {
Is this a bug or a deliberate change in behaviour?
bobray
April 14, 2022, 8:45pm
2
Good question. The only related commit message I found was this:
Fix xPDOFileCache->delete() and invalid calls to cacheManager->deleteTree()
But it’s from 2011, and the commit doesn’t change that value.
You can see why this was changed in this PR:
modxcms:3.x
← opengeek:xpdofilecache-delete-fix-3.x
opened 06:30PM - 31 Dec 19 UTC
Other xPDOCache implementations check for the multiple_object_delete option befo… re attempting to recursively remove cache entries that match the cache key provided to the delete() method. xPDOFileCache was not doing this, and further, if a directory existed with the cache key to be deleted, the directory was emptied of cache entries but the actual cache entry that was meant to be deleted was left in place.
Resolves #170 for 3.x branch
This was also changed for 2.x at the same time…
modxcms:2.x
← opengeek:xpdofilecache-delete-fix
opened 06:06PM - 31 Dec 19 UTC
Other xPDOCache implementations check for the `multiple_object_delete` option be… fore attempting to recursively remove cache entries that match the cache key provided to the delete() method. xPDOFileCache was not doing this, and further, if a directory existed with the cache key to be deleted, the directory was emptied of cache entries but the actual cache entry that was meant to be deleted was left in place.
Resolves #170 for 2.x branch
Thanks, for the links.
But my question is, why the default value is different for the 2 branches.
If ‘multiple_object_delete’ is not specified in the $options
array, then it’s default value is true
in 3.x and false
in 2.x which leads to inconsistent behavior between the branches.
2.x → third parameter for getOption()
is true
:
if ($this->getOption('multiple_object_delete', $options, true)) {
3.x → third parameter for getOption()
is false
:
if ($this->getOption(xPDO::OPT_CACHE_MULTIPLE_OBJECT_DELETE, $options, false)) {
This comment is the only explanation I can offer…
modxcms:2.x
← opengeek:xpdofilecache-delete-fix
opened 06:06PM - 31 Dec 19 UTC
Other xPDOCache implementations check for the `multiple_object_delete` option be… fore attempting to recursively remove cache entries that match the cache key provided to the delete() method. xPDOFileCache was not doing this, and further, if a directory existed with the cache key to be deleted, the directory was emptied of cache entries but the actual cache entry that was meant to be deleted was left in place.
Resolves #170 for 2.x branch
1 Like