문제

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);
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top