From 5f17dc9b5e47657bdd177fb728716ef7184b02b2 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 10 Sep 2013 07:17:05 +0200 Subject: [PATCH] Allow address book list to be cached. --- lib/controller/addressbookcontroller.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/controller/addressbookcontroller.php b/lib/controller/addressbookcontroller.php index ca25cc92..9048fb27 100644 --- a/lib/controller/addressbookcontroller.php +++ b/lib/controller/addressbookcontroller.php @@ -30,13 +30,24 @@ class AddressBookController extends BaseController { $app = new App($this->api->getUserId()); $addressBooks = $app->getAddressBooksForUser(); $response = array(); + $lastModified = 0; foreach($addressBooks as $addressBook) { - $response[] = $addressBook->getMetaData(); + $data = $addressBook->getMetaData(); + $response[] = $data; + if(!is_null($data['lastmodified'])) { + $lastModified = max($lastModified, $data['lastmodified']); + } } - $response = new JSONResponse( - array( + + $response = new JSONResponse(array( 'addressbooks' => $response, )); + + if($lastModified > 0) { + $response->setLastModified(\DateTime::createFromFormat('U', $lastModified) ?: null); + $response->setETag(md5($lastModified)); + } + return $response; }