Clear cache on vcard change/delete

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-05-03 15:11:26 +02:00
parent 34d97aa51c
commit 3ab53d000f
No known key found for this signature in database
GPG Key ID: F941078878347C0C
3 changed files with 31 additions and 8 deletions

View File

@ -112,6 +112,19 @@ class Application extends App {
} }
}); });
$clearPhotoCache = function($event) {
if ($event instanceof GenericEvent) {
/** @var PhotoCache $p */
$p = $this->getContainer()->query(PhotoCache::class);
$p->delete(
$event->getArgument('addressBookId'),
$event->getArgument('cardUri')
);
}
};
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
$user = $event->getSubject(); $user = $event->getSubject();
$syncService = $this->getContainer()->query(SyncService::class); $syncService = $this->getContainer()->query(SyncService::class);

View File

@ -103,14 +103,12 @@ class ImageExportPlugin extends ServerPlugin {
/** @var AddressBook $addressbook */ /** @var AddressBook $addressbook */
$addressbook = $this->server->tree->getNodeForPath($addressbookpath); $addressbook = $this->server->tree->getNodeForPath($addressbookpath);
$hash = md5($addressbook->getResourceId() . $node->getName());
$response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate'); $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
$response->setHeader('Etag', $node->getETag() ); $response->setHeader('Etag', $node->getETag() );
$response->setHeader('Pragma', 'public'); $response->setHeader('Pragma', 'public');
try { try {
$file = $this->cache->get($hash, $size, $node); $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
$response->setHeader('Content-Type', $file->getMimeType()); $response->setHeader('Content-Type', $file->getMimeType());
$response->setHeader('Content-Disposition', 'inline'); $response->setHeader('Content-Disposition', 'inline');
$response->setStatus(200); $response->setStatus(200);

View File

@ -26,15 +26,16 @@ class PhotoCache {
} }
/** /**
* @param string $hash * @param int $addressBookId
* @param string $cardUri
* @param int $size * @param int $size
* @param Card $card * @param Card $card
* *
* @return ISimpleFile * @return ISimpleFile
* @throws NotFoundException * @throws NotFoundException
*/ */
public function get($hash, $size, Card $card) { public function get($addressBookId, $cardUri, $size, Card $card) {
$folder = $this->getFolder($hash); $folder = $this->getFolder($addressBookId, $cardUri);
if ($this->isEmpty($folder)) { if ($this->isEmpty($folder)) {
$this->init($folder, $card); $this->init($folder, $card);
@ -132,10 +133,12 @@ class PhotoCache {
/** /**
* @param $hash * @param int $addressBookId
* @param string $cardUri
* @return ISimpleFolder * @return ISimpleFolder
*/ */
private function getFolder($hash) { private function getFolder($addressBookId, $cardUri) {
$hash = md5($addressBookId . ' ' . $cardUri);
try { try {
return $this->appData->getFolder($hash); return $this->appData->getFolder($hash);
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
@ -231,4 +234,13 @@ class PhotoCache {
} }
return ''; return '';
} }
/**
* @param int $addressBookId
* @param string $cardUri
*/
public function delete($addressBookId, $cardUri) {
$folder = $this->getFolder($addressBookId, $cardUri);
$folder->delete();
}
} }