Skip Navigation

[Résolu] How can I cache Views-generated Google Maps markers javascript?

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created Il y a 8 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 réponses, has 2 voix.

Last updated by Kris Haamer Il y a 8 années et 10 mois.

Assisted by: Luo Yang.

Auteur
Publications
#305690
Captura de tela 2015-05-23 20.26.15.png

I am trying to cache the javascript array generated by Views to be displayed on Google Maps. I'm generating the array from 1000+ posts and new posts are added only a few times per week. Thus the javascript array should be cached, not re-generated on every access. How would I go about doing this with Toolset/Views? Any advice would be appreciated.

Thanks.

Kris

#305859

Dear Kris,

Views is using wordpress build-in PHP class WP_Query to query the database, you can try other cache plugins, or use wordpress build-in cache feature:

More help:
http://codex.wordpress.org/Class_Reference/WP_Query
https://toolset.com/faq/working-with-caching-plugins/
https://codex.wordpress.org/WordPress_Optimization/Caching

#305863

Hi Luoy, yes, that's what I doing already post view-generation. The general site cache runs every 1 hour. What I need in this particular case though is to run the the view query only once per 24h. How would I achieve this? Thanks.

Kris

#305982

You can try wordpress build-in cache API Transients, for example:
1) create a custom shortcode in your theme/functions.php:

add_shortcode('cache-view-result', 'cache_view_result_func');
function cache_view_result_func($atts, $content){
    extract(  shortcode_atts( array(
		'name' => '',
		'expiration' => 24,
	), $atts ));
	$cache_name = 'cache_view_results_' . $name;
	if ( false === ( $res = get_transient( $cache_name ) ) ) {
		 $res = render_view( array('name' => $name) );
		 set_transient( $cache_name, $res, $expiration * HOUR_IN_SECONDS );
	}
	return $res;
}

2) use above shortcode in your content, like this:
[cache-view-result name="my-view-slug" expiration=24]

More help:
Transients API
https://codex.wordpress.org/Transients_API

#306002

Fantastic, thank you!

Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.