Skip to content

Commit 2b25a7c

Browse files
committed
Reduce one cache lookup
1 parent 218e080 commit 2b25a7c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Routing/RouterListener.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function onBeforeRouting(GetResponseEvent $event)
5454
}
5555

5656
$request->attributes->add($item->get());
57+
$request->attributes->set('_cache_hit', true);
5758
}
5859

5960
/**
@@ -70,11 +71,14 @@ public function onAfterRouting(GetResponseEvent $event)
7071
return;
7172
}
7273

73-
$item = $this->getCacheItem($request);
74-
if ($item->isHit()) {
74+
if ($request->attributes->has('_cache_hit')) {
75+
$request->attributes->remove('_cache_hit');
76+
// object is in cache all ready
7577
return;
7678
}
7779

80+
// Save to the cache
81+
$item = $this->getCacheItem($request);
7882
$item->set($request->attributes->all());
7983
$this->cache->save($item);
8084
}

0 commit comments

Comments
 (0)