Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: cache introspection (Cache::KEY) #51

Open
f3l1x opened this issue May 2, 2017 · 4 comments
Open

RFC: cache introspection (Cache::KEY) #51

f3l1x opened this issue May 2, 2017 · 4 comments

Comments

@f3l1x
Copy link
Member

f3l1x commented May 2, 2017

  • 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

@JanTvrdik
Copy link
Contributor

JanTvrdik commented May 2, 2017

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?

@milo
Copy link
Member

milo commented May 2, 2017

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).

@TomasVotruba
Copy link

(@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.)

@f3l1x
Copy link
Member Author

f3l1x commented May 9, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@JanTvrdik @milo @f3l1x @TomasVotruba and others