Question

UPDATE: I've decided to take the advice below and implement a Memcached tier in my app. Now I have another thought. Would it be possible/a good idea to do an AJAX request on a poll (say every five or ten minutes) that checks Memcached and then updates when Memcached has expired? This way the latency is never experienced by the end user because it's performed silently in the background.


I'm using Directed Edge's REST API to do recommendations on my web app. The problem I'm encountering is that I query for a significant number of recommendations in multiple places across the site, and the latency is significant, making the page load something like 2-5 seconds for each query. It looks terrible.

I'm not using Directed Edge's PHP bindings, and instead am using some PHP bindings I wrote myself. You can see the bindings on GitHub. I'm connecting to their API using cURL.

How can I cache the data I'm receiving? I'm open to any number of methods so long as they're fairly easy to implement and fairly flexible.

Here's an example of the client code for getting recommendations.

$de = new DirectedEdgeRest();
$item = "user".$uid;
$limit = 100;
$tags = "goal";
$recommendedGoals = $de->getRecommended($item, $tags, $limit);
Was it helpful?

Solution

You can cache to a file using serialize and file_put_contents:

file_put_contents("my_cache", serialize($myObject));

You could also cache to memcached or a database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top