caching icon indicating copy to clipboard operation
caching copied to clipboard

RFC: cache introspection (Cache::KEY)

Open f3l1x opened this issue 8 years ago • 4 comments

  • bug report - NO
  • feature request - YES
  • version: >2.4.0

What's about

A few days ago I was working on cache panel. My goal was to show all created cache files with expiration, size and many other things. It was quite easy, let say with little help of reflection.

My result look's like that.

selection_017

The thing is I cannot show cache key, because it's serialized in Cache object and passed to IStorage. I was reading it from FileStorage (that was my 1st implementation) and there is only md5 hash. I known I can inherit Cache object or create CacheFactory a everything gonna be allright, but I wont. I would like to see it also in my old projects.

Why it might be useful? At this time we have no cache tools or any other cache introspective tools. We can only create Cache object with IStorage and hope there's a cache file with this key (hash).

How to implement it

1) CacheFactory + inherit Cache object

It's good but only for new projects.

2) Store cache key under special tag

I think it's oukey, but little bit tricky.

$dependencies[Cache::TAGS] = ['__nette.cache.key' => $key];
$this->storage->write($key, $data, $dependencies);

3) Introduce new constant Cache::KEY

I consider this as best solution. It's clean and it shouldn't broke any existing code.

$dependencies[Cache::KEY] = $key;
$this->storage->write($key, $data, $dependencies);

What do you think guys? @dg @fprochazka @TomasVotruba @matej21 @JanTvrdik

f3l1x avatar May 02 '17 05:05 f3l1x

Well, first of all it seems like you would need an interface for getting all data / all keys, sth. like IStorage::readAll() / IStorage::readAllKeys(), except we can't put it on IStorage for both compatibility and performance reasons.

Maybe wrap in debug mode IStorage with some DebugStorage which would track the information?

JanTvrdik avatar May 02 '17 07:05 JanTvrdik

Panel looks nice, but I see many problems :) It should be universal, for any IStorage. But it requires change in storage interface. Something like readAll() which can be huge. And I would expect that key will correspond with real key, but key can be an array (or anythink).

milo avatar May 02 '17 07:05 milo

(@f3l1x Just to answer for your request: I don't use cache in very such an extend level, so my opinion would be very superficial and naive.)

TomasVotruba avatar May 02 '17 11:05 TomasVotruba

@JanTvrdik @milo Thank you for the reply. (@TomasVotruba thanks pal)

At this very first time I traverse all files in the cache folder (with prefix __) and read their metadata. Yes, IStorage::readAll would be nice but it's not necessary.

As @milo said, key might be array of anything, that could be a problem, but it depends on point of rendering, which would be the hard part.


I still think that passing Cache::KEY through the dependencies variable might be a easy change and the start point of something big.

f3l1x avatar May 09 '17 12:05 f3l1x