Skip to content

Commit

Permalink
Meet: expire cache at next event
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative authored and bastianallgeier committed Oct 14, 2024
1 parent ebc24aa commit f134a9d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
5 changes: 0 additions & 5 deletions site/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
'active' => true,
'type' => 'file'
],
'meet' => [
'active' => true,
'type' => 'file'
],
'pages' => [
'active' => true,
'type' => 'file',
Expand All @@ -17,7 +13,6 @@
'features-for-clients',
'home',
'love',
'meet',
'partners',
'scenario-education',
'themes',
Expand Down
6 changes: 0 additions & 6 deletions site/config/config.getkirby.test.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<?php

return [
'cache' => [
'meet' => [
'active' => true,
'type' => 'file'
],
],
'debug' => true,
'email' => [
'transport' => [
Expand Down
1 change: 0 additions & 1 deletion site/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

if (empty($key) === false && get('key') === $key) {
kirby()->cache('diffs')->flush();
kirby()->cache('meet')->flush();
kirby()->cache('pages')->flush();
kirby()->cache('reference')->flush();
}
Expand Down
18 changes: 15 additions & 3 deletions site/controllers/meet.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

return function () {
use Kirby\Cms\App;

return function (App $kirby) {
$events = collection('events');
$upcoming = $events->filterBy('isUpcoming', true);

// expire the cache 2h after the next upcoming event starts
if ($next = $upcoming->first()) {
$time = $next->datetime()->getTimestamp() + (60 * 60 * 2);
$kirby->response()->expires($time);
$kirby->response()->header('Expires', gmdate('D, d M Y H:i:s T', $time));
}

return [
'events' => $events = collection('events'),
'upcoming' => $events->filterBy('isUpcoming', true),
'events' => $events,
'upcoming' => $upcoming,
'past' => $events->filterBy('isUpcoming', false),
'gallery' => $events->images()->shuffle(),
];
Expand Down
2 changes: 1 addition & 1 deletion site/models/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function isMeetup(): bool

public function isUpcoming(): bool
{
return $this->date()->toTimestamp() >= time();
return $this->datetime()->getTimestamp() >= time();
}

public function shortTitle(): Field
Expand Down

0 comments on commit f134a9d

Please sign in to comment.