OleVik/grav-plugin-twigfeeds

Cache results

OleVik opened this issue · 8 comments

Implement a caching-system to store files locally and only retrieve new ones when updates are available.

  • Store files in /cache or /data
  • Check for new results before Grav's cache runs
  • Compare to cached data
    • If new data, retrieve, save, and delete old data

See v2.0.0-RC1 for a release candidate.

Local storage

Generate a decently safe filename:

$feed_name = preg_replace("/[^a-z0-9\.]/", "", strtolower($result->getTitle()));
$timestamp = $result->getDate()->getTimestamp();
$filename = $timestamp . '-' . $feed_name . '.feed';

Store file in /data (see Form-plugin):

$locator = $this->grav['locator'];
$path = $locator->findResource('user://data', true);
$fullFileName = $path . DIRECTORY_SEPARATOR . $filename;
$file = File::instance($fullFileName);
$file->save($feed);

I wonder whether this will solve the problem I have been happening. If Caching is on, then the results of the plugin show on the first time the sidebar is loaded, but never after that.

It should not, as caching should already catch any rendered content from Twig-templates and store it as it usually would. The outline above is simply to plan for a workflow that requires less overhead in retrieving new content. I replied in the forum post.

Do you have any plan about this? I'd like to be able to cache the results of my feeds, particularly since the blog is also mine. Better yet would be to be able to bust the cache when I want.

If you want any help with this, I'd be glad to lend you a hand.

I do have a plan to create the caching-mechanism sometime this week, plugging into Grav's asset-cache for proper handling by the CLI. I'd be very happy to get some testing and feedback once the RC is out, I'll tag it as a pre-release and notify this issue.

I'll test it once it's ready.

There is now a release candidate which implements the caching-mechanism: v2.0.0-RC1.

As it is a release candidate it is published as a GitHub pre-release, and branched as "v2". Thus the new functionality should not interfere with stable installations. Tested with and without Grav's internal cache, more details in README for branch v2.

Any input and error reports are very welcome!

@amtur8 Have you had a chance to test v2.0.0-RC1 of the plugin?

Release v2.0.2 contains cache-mechanism and associated cache, static_cache, and debug options. See updated README.