Permalink
Browse files

perf(simplecache): Faster serving in case symlink not used

We only need to boot and check `lastcache` time if the client’s given view
file doesn’t already exist. This is safe because the path is already verified
not to contain `..`.
  • Loading branch information...
mrclay committed Jun 30, 2015
1 parent 3ed70fb commit 85c2e888b5d32d4dbe25bd00c3a3ef139a3f384e
Showing with 9 additions and 5 deletions.
  1. +9 −5 engine/classes/Elgg/Application/CacheHandler.php
@@ -107,6 +107,15 @@ public function handleRequest($path) {
$etag = "\"$ts\"";
$this->handle304($etag);
+ // trust the client but check for an existing cache file
+ $filename = $config->getVolatile('dataroot') . "views_simplecache/$ts/$viewtype/$view";
+ if (file_exists($filename)) {
+ $this->sendCacheHeaders($etag);
+ readfile($filename);
+ exit;
+ }
+
+ // the hard way
$this->application->bootCore();
elgg_set_viewtype($viewtype);
@@ -117,11 +126,6 @@ public function handleRequest($path) {
$lastcache = (int)$config->get('lastcache');
$filename = $config->getVolatile('dataroot') . "views_simplecache/$lastcache/$viewtype/$view";
- if (file_exists($filename)) {
- $this->sendCacheHeaders($etag);
- readfile($filename);
- exit;
- }
if ($lastcache == $ts) {
$this->sendCacheHeaders($etag);

0 comments on commit 85c2e88

Please sign in to comment.