Reputation: 838
I have been using the GAE or Google App Engine for PHP for sometime and use a basic cloudSQL to read data from it. Since it been a few months and inorder to optimize it I wanted to reduce the number of reads the auto fill in the form uses to read names from Table. As of not it is as high as 80k per day which is insanely high for a simple form.
Since Google does not allow me to write to a text file or any other temp file without a bucket ( I don't have bucket .. for that matter why do we need one? ) I figured I use a cache feature that I can have it refresh every day and then do the read queries of from the cache instead of the actual Table hence reducing the number of reads.
That's were I ran into a wall. I am a beginner in this and all though a experienced pro may understand this
https://developers.google.com/appengine/docs/php/memcache/#PHP_PHP_memcache_implementation
I have no idea what it says.
Can any one teach me or tell me how to use the cache feature of GAE? I tried searching for a "How to" but didn't find one.
My autocomplete function looks like this
setAutoComplete("name", "results1", "autocomplete.php?part=");
so it calls autocomplete php whenever a text is entered in the form after a keyup.
And the SQL part of it looks like this
$sql = "SELECT SUBSTRING(NAME,1,300) AS Name FROM `Table` WHERE Name LIKE '{$p}%'";
// Check Query ran sucessfully
$query = mysql_query($sql) or die("Query failed: " . mysql_error() . " Actual query: " . $query);
//Create an array with the results
$results = array();
while ($user = mysql_fetch_object($query)) {
$results[] = $user -> Name;
}
//using JSON to encode the array
echo json_encode($results);
Hope this is able to paint a clear picutre. Thank you in advance from me and any one else who might come here looking for a similar answer.
P.S - I am reading PHP Manual not really helping much.
Upvotes: 0
Views: 1730
Reputation: 139
I used both memcache API's supported in GAE(Memcache and Memcached) .This is the Memcache code.(I assume your query is working properly)
$data = array();
$key = 'memcahcetestkey';
$memcache = new Memcache;
$data = $memcache->get($key);
if ($data === false) {
$data = $results ;//yourQueryResult;
$memcache->set($key, $data);
}
Then check your memcache values using $your_memecach_array=$memcache->get($key);
Upvotes: 1