Implement initial expiry support

Sun, 01 Aug 2010 12:17:31 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 01 Aug 2010 12:17:31 +0100
changeset 14
578214a34ded
parent 13
db66a09dc0b6
child 15
87ef478bf7fc

Implement initial expiry support

util/memcache.lua file | annotate | diff | comparison | revisions
--- a/util/memcache.lua	Sun Aug 01 12:17:12 2010 +0100
+++ b/util/memcache.lua	Sun Aug 01 12:17:31 2010 +0100
@@ -13,15 +13,22 @@
 	local _deleted = {};
 	
 	function cache:set(key, flags, expires, data)
-		if expires ~= 0 then
-			return false, "Expiry is not currently implemented";
+		_flags[key] = flags;
+		if expires > 0 then
+			if expires <= max_expires_seconds then
+				expires = now() + expires;
+			end
+			_expiry[key] = expires;
 		end
-		_flags[key] = flags;
 		_data[key] = data;
 		return true;
 	end
 	
 	function cache:get(key)
+		local expires = _expiry[key];
+		if expires and expires > now() then
+			self:delete(key);
+		end
 		return _flags[key], _data[key];
 	end
 	

mercurial