Skip to content

Commit

Permalink
Merge pull request #14 from amyboyd/prevent-caching-of-random-image
Browse files Browse the repository at this point in the history
Fix caching of effect-styled images.
  • Loading branch information
DesignyourCode committed Nov 26, 2015
2 parents c33e5e7 + 4caf86f commit bbbab96
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions public_html/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function serve($width, $height, $person)
$response = $app->response();
$response['Content-Type'] = 'image/jpeg';

$cacheKey = getCacheKey($width, $height, $person);
$cacheKey = getCacheKey($width, $height, $person, $request);
if ($canRequestBeCached && isFileCached($cacheKey)) {
$img = new SimpleImage(getCacheFile($cacheKey));
} else {
Expand All @@ -169,12 +169,12 @@ function serve($width, $height, $person)
$img->crop(0, $y1, $width, $y2);
}

if ($canRequestBeCached) {
cacheImage($cacheKey, $img);
}
$img = applyFilters($img);
}

$img = applyFilters($img);
if ($canRequestBeCached) {
cacheImage($cacheKey, $img);
}

$img->output();
}
Expand All @@ -192,9 +192,9 @@ function canRequestBeCached(Request $request, $person)
return true;
}

function getCacheKey($width, $height, $person)
function getCacheKey($width, $height, $person, Request $request)
{
return "$width-$height-$person";
return "$width-$height-$person-" . md5(serialize($request->params()));
}

function isFileCached($cacheKey)
Expand Down

0 comments on commit bbbab96

Please sign in to comment.