Skip to content

Commit 00b07c0

Browse files
Add cache control to getTile and downloadImage (#362)
1 parent f44c7c8 commit 00b07c0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Module/WebClient.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ public function getJP2Header() {
203203
}
204204

205205
/**
206-
* Returns a full jpeg2000 image as a tif
206+
* Returns a full jpeg2000 image converted to the designated image type (png/jpg/webp)
207+
* extension is validated via the input validator.
207208
*/
208209
public function downloadImage() {
209210
include_once HV_ROOT_DIR.'/../src/Database/ImgIndex.php';
@@ -244,6 +245,10 @@ public function downloadImage() {
244245
$image['sunCenterOffsetParams']
245246
);
246247

248+
// downloadImage requests are very deterministic, so make sure the client knows these are safe to cache.
249+
// 30days (60sec * 60min * 24hours * 30days)
250+
header("Cache-Control: max-age=2592000");
251+
247252
// Save and display
248253
$tile->save();
249254
$tile->display();
@@ -398,6 +403,10 @@ public function getTile() {
398403
$image['sunCenterOffsetParams']
399404
);
400405

406+
// getTile requests are very deterministic, so make sure the client knows these are safe to cache.
407+
// 30days (60sec * 60min * 24hours * 30days)
408+
header("Cache-Control: max-age=2592000");
409+
401410
// Save and display
402411
$tile->save();
403412
$tile->display();
@@ -1141,7 +1150,7 @@ public function getRandomSeed() {
11411150
// Output result
11421151
$this->_printJSON(json_encode($response));
11431152
}
1144-
1153+
11451154
/**
11461155
* Returns an embeddable image showing LASCO C2/C3 data leading up to
11471156
* the selected eclipse.
@@ -1177,7 +1186,7 @@ public function getEclipseImage() {
11771186
// Create the base screenshot image
11781187
include_once HV_ROOT_DIR.'/../src/Image/Composite/HelioviewerScreenshot.php';
11791188
$screenshot = new Image_Composite_HelioviewerScreenshot(
1180-
$layers, $events, false, false, $celestialBodies, false, 'earth', 0, 0, $now_str, $roi,
1189+
$layers, $events, false, false, $celestialBodies, false, 'earth', 0, 0, $now_str, $roi,
11811190
['grayscale' => true, 'eclipse' => true, 'moon' => $this->_options['moon']]
11821191
);
11831192
$screenshot->display();

0 commit comments

Comments
 (0)