# Cache and scheduled posts

**URL:** <https://forum.getkirby.com/t/cache-and-scheduled-posts/5769>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 15, 2016, 12:38pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769 "2016-11-15T12:38:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rppld](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rppld/32/2981_2.png) [@rppld](https://forum.getkirby.com/u/rppld)\
**Post date:** [November 15, 2016, 12:38pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/1 "2016-11-15T12:38:17Z")

</div>

Hi all,

I currently have an issue that I’m not sure how to solve yet: Basically we schedule posts through defining a future date as the post date. So as soon as the post-date of a scheduled post is in the past, it’s supposed to show up in the blog. The problem is, the cache doesn’t get flushed when that happens, and the post doesn’t show up on the site without an additional refresh.

Did anyone run into this already and can point me into the right direction?

Best,  
Philipp

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 15, 2016, 3:21pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/2 "2016-11-15T15:21:08Z")

</div>

Kirby does not have a daemon process that is continuously running, so it can’t automatically flush the cache.

I think the best way would be to create a Kirby plugin that checks if any post has become visible since the last check. The plugin can then flush the cache. Plugins are always loaded, even if the cache is used, so they will always be able to check.

---

<div class="post-metadata">

**Author:** ![rppld](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rppld/32/2981_2.png) [@rppld](https://forum.getkirby.com/u/rppld)\
**Post date:** [November 15, 2016, 3:38pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/3 "2016-11-15T15:38:22Z")

</div>

Okay thanks I’ll explore this route!

---

<div class="post-metadata">

**Author:** ![Andi-Lo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andi-lo/32/2582_2.png) [@Andi-Lo](https://forum.getkirby.com/u/Andi-Lo)\
**Post date:** [November 15, 2016, 7:13pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/4 "2016-11-15T19:13:15Z")

</div>

> [@lukasbestle](#):
>
> Kirby does not have a daemon process that is continuously running, so it can’t automatically flush the cache.

So how does kirby manage the cache when using static file caching?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 15, 2016, 7:15pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/5 "2016-11-15T19:15:49Z")

</div>

What do you mean exactly?

---

<div class="post-metadata">

**Author:** ![Andi-Lo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andi-lo/32/2582_2.png) [@Andi-Lo](https://forum.getkirby.com/u/Andi-Lo)\
**Post date:** [November 15, 2016, 7:19pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/6 "2016-11-15T19:19:01Z")

</div>

Like there are a couple of cache busting methodologies for CSS and JS but how does kirby manage the cached files and how do they get outdated and refreshed? Like does kirby flush the cache ever or do you have to manage all by hand?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 15, 2016, 7:22pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/7 "2016-11-15T19:22:37Z")

</div>

Kirby [checks for the file modification date](https://github.com/getkirby/kirby/blob/master/kirby.php#L595-L607) when trying to retrieve something from the cache. Items are flushed from the cache once they are older than the content.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 15, 2016, 7:25pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/8 "2016-11-15T19:25:36Z")

</div>

> [@Andi-Lo](#):
>
> Like does kirby flush the cache ever or do you have to manage all by hand?

Also, the cache is flushed whenever you create an new or update an existing page.

---

<div class="post-metadata">

**Author:** ![Andi-Lo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andi-lo/32/2582_2.png) [@Andi-Lo](https://forum.getkirby.com/u/Andi-Lo)\
**Post date:** [November 15, 2016, 7:55pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/9 "2016-11-15T19:55:51Z")

</div>

Thats what I wanted to know. 🙂 thanks for clarification

---

<div class="post-metadata">

**Author:** ![Andi-Lo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andi-lo/32/2582_2.png) [@Andi-Lo](https://forum.getkirby.com/u/Andi-Lo)\
**Post date:** [November 28, 2016, 9:41pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/10 "2016-11-28T21:41:14Z")

</div>

Just got into trouble with the cache and thought that I post it here instead of opening a new topic.

My question is how can I flush the cache manually? The docs say that I can use something like `cache::flush()`?  
But my question is also where do I need to place that piece of code in order to get executed?

I am using a one-pager where every section of the page is a snippet. The news.php snippet is responsible for displaying Facebook events. The fetching of those events happens in a plugin called “FacebookEvents” (via api) and it then stores it locally in `content/1-news/`. When the event is expired it flushes the `content/1-news/` folder and requests the next event, storing it again.  
Now when I have caching activated this is not working anymore. The code for checking Facebook for new events will not be executed and the content (old event) will get served from cache until some action that makes the internal Kirby flush the cache gets executed.

This is how the snippet news.php looks like:

```php
  <?php
    // get the $page object 
    $news = $pages->findByURI('news');

    $fbe = FacebookEvents($news);
    // if the event expired getNews will return the next event, else the locally stored
    $fb_event = $fbe->getNews('12345');
  ?>

```

How can I flush the cache in a plugin? What code will get executed if caching is activated? Do I need a controller or something for the “home” template?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 28, 2016, 10:02pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/11 "2016-11-28T22:02:53Z")

</div>

Yes, you can cache the flush from the plugin. The code in the plugin will always be executed, even with cache enabled.

You plugin could check if there is a new event (as compared to what is in the cache) and if yes, it could flush the cache.

---

<div class="post-metadata">

**Author:** ![roka](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roka/32/15017_2.png) [@roka](https://forum.getkirby.com/u/roka)\
**Post date:** [December 8, 2017, 2:36pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/12 "2017-12-08T14:36:42Z")

</div>

Did you explore this? I have exactly the same setup and problem.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:30pm UTC](https://forum.getkirby.com/t/cache-and-scheduled-posts/5769/13 "2025-02-06T17:30:20Z")

</div>


