Jump to content

Pages Block. Refresh one time per day. How?


Recommended Posts

Hi guys,

I'm trying to create a quote of the day Pages block to show at the home page. I have a Pages database with many quotes already and I'm able to visualize on my home page one quote.
However, the block refreshes whenever caching time is over and I want it to refresh the text and pull a random quote one time per 24 hours only.
In previous versions of IPS it was possible to control the caching time per block, but now it is not as long as I see. Is this correct?

How can I somehow make it refresh only one time per 24 hours / day? Any extra code to put in the template for the block or something? 
Or any other suggestions to make this work preferably via a block?

Link to comment
Share on other sites

3 hours ago, Matt said:

You'll need to do the caching/refresh logic inside the block itself if you want more control over how long the item is cached for.

Thank you very much for your reply, @Matt!

Can you provide some further guidence for this? Any sample code?

Anything I can simply copy/paste + eventually do small modifications to make it work?

Link to comment
Share on other sites

  • Management

It really depends on how you have structured your database and code.

There are areas of the software that we manage caching independently of the rest of the suite, and when we do this, we typically store the data like so:

\IPS\Data\Store::i()->yourDataKey = [ 'time' => time(), 'data' => [ ... your data here ... ];

Then when reading you can check 'time' against the current time and make a decision as to whether to use the data or refresh it.

For an example of this, check out /system/Widget/Widget.php, around line 879

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
×
×
  • Create New...