Cache in filecache#28166
Conversation
|
|
||
| /** | ||
| * @var CappedMemoryCache | ||
| */ |
There was a problem hiding this comment.
testing revealed that we instantiate more than one instance of this class which works against the caching effect.
| if (!$data and is_string($file)) { | ||
| if (isset($this->partial[$file])) { | ||
| $data = $this->partial[$file]; | ||
| return $this->partial[$file]; // return here, no need cache partial entries |
There was a problem hiding this comment.
are we sure this is not necessary?
| /** | ||
| * @var CappedMemoryCache | ||
| */ | ||
| private static $metaDataCache = null; |
There was a problem hiding this comment.
um leftover code from the previous attempt.
|
@mrow4a would be good if you could also check this out. I remember you looked into wasteful DB queries related to file cache. Maybe you have more insights. Didn't you have a PR adressing this or some piece of this differently ? |
|
Will have a look also later, looks really promising, it is something I wanted to have. There is one disavantage -> if someone forgets to use CacheIndex somewhere and uses filecache directly to write (read is ok) -> 💥 |
|
Any new comments? I would really see sth like that be merged. Would small "filecache code" refactor and protection be needed here? |
|
I'm not sure. It feels like a workaround on top of a sub-par architecture. On the other hand, caching stuff locally is what we've been doing everywhere with other things to prevent talking to the DB repeatedly. |
|
moved to triage, assuming this will not be ready for 10.0.3 |
e0e3d27 to
d4dc116
Compare
|
Rebased |
d4dc116 to
3783534
Compare
|
encryption also needs changes: owncloud/encryption#13 |
|
8.2 -> 10.0.3beta2 upgrade succeeded with this - which will have helped speed up the upgrade process for large amounts of reshares when coming from 8.2. |
|
Custom cache implementations would not benefit from this and might not even extend from our The only advantage of having it static here is the ability to quickly clear it from various locations, while normally you should go to the storage and do a |
|
Also I wonder if this should/could be implemented as a CacheWrapper instead. We might lose the ability to clear it from outside unless we keep the staticness. |
| } | ||
|
|
||
| private function fixTypes(array &$data) { | ||
| $data['fileid'] = 0 + $data['fileid']; |
There was a problem hiding this comment.
do we really need this here for caching ? I expect to see potential additional issues
There was a problem hiding this comment.
never mind, I see this was moved from another place
|
Happy to postpone this. |
|
@PVince81 The initial implementation was a cache wrapper: https://github.com/owncloud/core/pull/28165/files Nice and clean approach ... isn't it? Unfortunately, we
I added the necessary things we need to do: https://github.com/owncloud/core/pull/28166/files#diff-b4012cb6106f634acc5ff12ef395021fR85-R87 so ... no this cannot be an instance variable ... because ... still too much crappy code in other places. |
Argh, you're right |
|
I can see one disadvantage - if new code is written which writes to filecache, dev needs to be aware that cache needs to be cleaned with that static function. Apart from that - if no fragment of the code which writes to filecache has not been forgoten - looks good. |
| * | ||
| * FIXME first, refactor this class as an entity and add any necessary methods to its mapper | ||
| * FIXME then, get rid of all the places that directly touch the tables | ||
| * FIXME finally, make this private non-static |
There was a problem hiding this comment.
Do you plan it to have as separate PR? Do you expect it to be large change later?
| $result = $this->connection->executeQuery($sql, $params); | ||
| $data = $result->fetch(); | ||
|
|
||
| //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO |
There was a problem hiding this comment.
Well, not sure if you removed the hack, so FIXME still needs to stay
There was a problem hiding this comment.
Whole logic is not changed, and under function fixTypes
| protected $connection; | ||
|
|
||
| /** | ||
| * caches 2048 filecache rows |
There was a problem hiding this comment.
Why 2048? This PR usecase is I guess a repetitive calls during GET and PUT. Not sure if we need more then 32 rows in cache. What do you think? Won't it impact PROPFIND memory usage too much?
| ') AND `fileid` = ? '; | ||
| $this->connection->executeQuery($sql, $params); | ||
|
|
||
| self::$metaDataCache->clear(); |
There was a problem hiding this comment.
I am not sure if this shouldnt be as first line. There is small chance your filecache will be out of sync for very small time (not sure if this is that important)
| if ($entry['mimetype'] === 'httpd/unix-directory') { | ||
| $this->removeChildren($entry); | ||
| } | ||
| self::$metaDataCache->clear(); |
| } else { | ||
| $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); | ||
| } | ||
| self::$metaDataCache->clear(); |
|
|
|
Safer, alternative approach to this PR by fixing the app logic - #31486 |
| 'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'), | ||
| 'path_hash' => $query->createNamedParameter(\md5('apps/files/tests/deleteorphanedtagsjobtest.php')), | ||
| ])->execute(); | ||
| if (Cache::$metaDataCache !== null) { |
There was a problem hiding this comment.
Clear metadata cache before executing the query.
| ); | ||
| $output->write("deleting files for storage $numericId ... "); | ||
| $count = $queryBuilder->execute(); | ||
| if (Cache::$metaDataCache !== null) { |
There was a problem hiding this comment.
clear before executing the query
| $filesQuery->setParameter(2, \md5('file' . $i)); | ||
| $filesQuery->execute(); | ||
| } | ||
| if (Cache::$metaDataCache !== null) { |
| '', '4', '3', '163', '1499256550', '1499256550', | ||
| '0', '0', '595cd6e63f375', '27', 'NULL')"; | ||
| $this->connection->executeQuery($query); | ||
| if (Cache::$metaDataCache !== null) { |
| } | ||
|
|
||
| $builder->execute(); | ||
|
|
|
Closing in favor of OCIS. |
alternative approach to #28165