[TYPO3-dev] Question about TYPO3 7.2 new cf-based image size cache

Christian Reiter cr at cNOSPAMxd.de
Sat May 30 13:27:13 CEST 2015


TYPO3 7.2. has switched from old "cache_imagesizes" table to a caching 
framework implementation.

I have some questions here.

In the old version (6.2) "getCachedImageDimensions" worked like this

   $md5Hash = md5($fileStatus['mtime'] . $fileStatus['size']);

   $cachedImageDimensions =
   $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
    'md5hash, md5filename, imagewidth, imageheight',
    'cache_imagesizes',
    'md5filename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(
       md5($imageFile),   'cache_imagesizes'
    )
);

Note the  key to actually "get" cached dimensions is a hash of the full 
filename.
Then the md5hash of mtime and size is used to see whether the entry is 
still valid.
The database records additionally contain the filename, width and height 
in cleartext.

In the new 7.2 version the cache key (identifier) is made from mtime and 
size like this:

   protected function generateCacheKeyForImageFile($filePath) {
     $fileStatus = stat($filePath);
     return sha1($fileStatus['mtime'] . $fileStatus['size']);
   }

To get the cached dimensions:

   $statusHash = $this->generateCacheKeyForImageFile($filePath);
   ...
   $cachedImageDimensions = $cache->get($statusHash);

So we identify entries not by filename but only by hash of mtime and size.

Code is in TYPO3\CMS\Core\Imaging\GraphicalFunctions

Question 1.
It seems two or more different files that have same mtime and filesize 
will get the same $statusHash and return the same cache entry.
However it is possible they have different dimensions.
But all of them will get the same cached dimensions returned which will 
be wrong for all but one.

Question 2.
Let's assume the file has changed. As the comments in the code say, we 
want to delete the cache entry if we know the file has changed.

Obviously we can't use a key made from mtime and filesize to identify 
the cache entry we want to remove, because those parameters have changed 
by definition (that is the reason why we want to remove the entry).

So to delete the entry, the 7.2 version says
$cache->remove($filePath);

but earlier it used $cache->set($statusHash, $imageDimensions) and 
$cache->remove($statusHash) to set and get the entries, and as we saw 
that is built only from mtime and filesize which have changed.

Shouldn't cache->set/get and cache->remove use the same identifier?

It certainly looks like that 
TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend

Or am I completely misunderstanding how the caching framework operates?


Question 3
In the old version the cache_imagesizes was easy to access because it 
was possible to clear entries by filename.
If I knew something had changed files x,y,z -  I could directly flush 
the cache_imagesizes entries for them.

The new cache seems  much more difficult to handle because it lacks the 
filename to access it.
A great way would be if I could cache->flushByTag() with the filename, 
and both the original and any resized versions derived from an original 
filename could be tagged by that.
But the new image cache doesn't use tags at all.


Can anyone put me on the right track with this cache implementation?

Best regards,

Christian






More information about the TYPO3-dev mailing list