<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -14,3 +14,4 @@ mysql-proxy --proxy-lua-script=mysql-proxy-cache.lua
 
 Then, point your application to mysql proxy on port 4040 instead of 3306. Make sure you specify 127.0.0.1 as the host instead of localhost, otherwise you won't connect to mysql proxy.
 
+Default Timeout for data is 30 seconds. To change this, as it is rather low, and set this way for testing, edit the variable cache_timeout it mysql-proxy-cache.lua</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,10 @@
 require('luarocks.require')
 require('md5')
 require('Memcached')
-
 local memcache = Memcached.Connect()
 cache_hits = 0
 cache_misses = 0
-
+cache_timeout = 30
 function is_query(packet)
     return packet:byte() == proxy.COM_QUERY
 end
@@ -21,29 +20,31 @@ end
 function cache_get(query)
     local result = deserialize(memcache:get(to_hash(query)))
     if result then
-        print('HIT: '..to_hash(query)..' ('..query..')')
+--        print('HIT: '..to_hash(query)..' ('..query..')')
         cache_hits = cache_hits + 1
     else
-        print('MISS: '..to_hash(query)..' ('..query..')')
+--      print('MISS: '..to_hash(query)..' ('..query..')')
         cache_misses = cache_misses + 1
     end
-    
-    print('Cache hit ratio: '..cache_hits..'/'..cache_misses..' = '..cache_hits/cache_misses)
-    
+
+--    print('Cache hit ratio: '..cache_hits..'/'..cache_misses..' = '..cache_hits/cache_misses)
+
     return result
 end
 
 function cache_set(result_packet)
+    local resultset_is_needed = false
     local query = result_packet.query:sub(2)
     local field_count = 1
-    local fields = result_packet.resultset.fields 
+    local fields = result_packet.resultset.fields
     local resultset = {rows={}, fields={}}
-    
-    print('SET: '..to_hash(query)..' ('..query..')')
-  
+
+  --  print('SET: '..to_hash(query)..' ('..query..')')
+
     while fields[field_count] do
         local field = fields[field_count]
-        table.insert(resultset.fields, {type=field.type, name=field.name})
+	--added third option, expiry time.
+        table.insert(resultset.fields, {type=field.type, name=field.name} )
         field_count = field_count + 1
     end
 
@@ -51,7 +52,7 @@ function cache_set(result_packet)
         table.insert(resultset.rows, row)
     end
 
-    memcache:set(to_hash(query), serialize(resultset))
+    memcache:set(to_hash(query), serialize(resultset), cache_timeout)
 end
 
 function serialize(o)
@@ -67,7 +68,7 @@ function serialize(o)
     elseif o_type == &quot;table&quot; then
         table.insert(result, &quot;{&quot;)
         for key, value in pairs(o) do
-            for i, str in pairs({&quot;[&quot;, serialize(key), &quot;]=&quot;, 
+            for i, str in pairs({&quot;[&quot;, serialize(key), &quot;]=&quot;,
                                 serialize(value), &quot;,&quot;}) do
                 table.insert(result, str)
             end
@@ -92,9 +93,6 @@ function deserialize(s)
     end
 end
 
-
-
-
 function read_query( packet )
     if is_query(packet) then
         local query = packet:sub(2)
@@ -105,19 +103,18 @@ function read_query( packet )
                 -- Cache hit
                 proxy.response.type = proxy.MYSQLD_PACKET_OK
                 proxy.response.resultset = resultset
-                
+
                 return proxy.PROXY_SEND_RESULT
             else
                 -- Cache miss
-                proxy.queries:append(1, packet)
-                
+                proxy.queries:append(1, packet,{resultset_is_needed = true})
+
                 return proxy.PROXY_SEND_QUERY
             end
         end
     end
 end
 
-
 function read_query_result(result_packet)
     -- This only gets called if the proxy.queries queue is modified
     cache_set(result_packet)</diff>
      <filename>mysql-proxy-cache.lua</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2379fd334f63bb4e432fd5b30de05b99abca170b</id>
    </parent>
  </parents>
  <author>
    <name>Daniel Lockard</name>
    <email>danlock2@daniel-lockards-macbook.local</email>
  </author>
  <url>http://github.com/clofresh/mysql-proxy-cache/commit/6f21baa7557665cfa22c1e072ac383268e9dd260</url>
  <id>6f21baa7557665cfa22c1e072ac383268e9dd260</id>
  <committed-date>2009-07-08T14:00:37-07:00</committed-date>
  <authored-date>2009-07-08T14:00:37-07:00</authored-date>
  <message>Modified mysql-proxy-cache.lua so that it works again. Added a timeout for the cache.</message>
  <tree>4fa4af0106bb30272857d03f01161fae5d20193b</tree>
  <committer>
    <name>Daniel Lockard</name>
    <email>danlock2@daniel-lockards-macbook.local</email>
  </committer>
</commit>
