Jump to content

cache methods


RobertP

Recommended Posts

just checking to see if this is the correct cache method to use?

 

var serverCache = [];

$(document).ready(function(){
$(".tooltip").tooltip({
	bodyHandler:function(){
		serverName = $(this).html();
		if(serverCache[serverName]){
			$("#tooltip").html(serverCache[serverName]);
		}
		else{
			$("#tooltip").html("Loading...");
			$.ajax({
				url:"index.php?sub=serverInfo&server="+serverName,
				context:$("#tooltip"),
				success:function(data){
					serverCache[serverName] = data;
					$("#tooltip").html(serverCache[serverName]);
				}
			});
		}
		return "";
	},
	showURL:false,
	track:true,
	delay:0
});
});

Link to comment
https://forums.phpfreaks.com/topic/257577-cache-methods/
Share on other sites

Looks fine to me. Depends of course on how many tooltips there are? If it's a reasonable number then I would load them all in the first call, instead of one per call. The bottleneck, as you've identified, is in waiting for the request. If the tooltips are used frequently, then I would even consider just defining them as the page is loaded. There's no sense in using AJAX if it's degrading the performance.

Link to comment
https://forums.phpfreaks.com/topic/257577-cache-methods/#findComment-1320391
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.