1
0
Fork 0
mirror of synced 2024-09-06 12:51:43 +12:00
appwrite/app/controllers/shared/cache.php

24 lines
879 B
PHP
Raw Normal View History

2022-07-08 03:45:24 +12:00
<?php
use Utopia\App;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
App::shutdown(function (Database $dbForProject, string $cacheKey, string $cachePath) {
if (!empty($cacheKey) && !empty($cachePath)) {
$cacheLog = $dbForProject->getDocument('cache', $cacheKey);
if ($cacheLog->isEmpty()) {
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
'$id' => $cacheKey,
'accessedAt' => time(),
'path' => $cachePath
])));
} else {
$cacheLog->setAttribute('accessedAt', time());
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
}
}
}, ['dbForProject', 'cacheKey', 'cachePath'], 'cache');