diff -Naur memcached-1.2.5/config.h.in memcached-1.2.5-patched/config.h.in
--- memcached-1.2.5/config.h.in	2008-03-03 21:59:48.000000000 +0200
+++ memcached-1.2.5-patched/config.h.in	2008-03-11 16:13:17.000000000 +0200
@@ -6,6 +6,12 @@
 /* machine is littleendian */
 #undef ENDIAN_LITTLE
 
+/* magic negative ttl to use as a 0 equivalent for permanent items */
+#undef FEATURE_PERMITEM_MAGICFORZERO
+
+/* switches on the permitems feature */
+#undef FEATURE_PERMITEM_ON
+
 /* Define this if you have daemon() */
 #undef HAVE_DAEMON
 
diff -Naur memcached-1.2.5/configure memcached-1.2.5-patched/configure
--- memcached-1.2.5/configure	2008-03-03 21:59:49.000000000 +0200
+++ memcached-1.2.5-patched/configure	2008-03-11 16:13:12.000000000 +0200
@@ -1298,6 +1298,13 @@
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --disable-dependency-tracking  speeds up one-time build
   --enable-dependency-tracking   do not reject slow dependency extractors
+  --enable-perm-items     Enable writing permanent items (not subject to LRU
+                          replacement) via negative ttl hack (default: no)
+  --enable-perm-items-magic=number
+                          Use a magic negative ttl for permanent items that
+                          should never expire (equivalent to 0) for those
+                          whose clients can't send '-0' ttl. Requires
+  --enable-perm-items     (default: none)
   --enable-64bit          build 64bit verison
   --enable-threads        support multithreaded execution
 
@@ -3726,6 +3733,82 @@
 
 fi
 
+echo "$as_me:$LINENO: checking whether to enable permanent items" >&5
+echo $ECHO_N "checking whether to enable permanent items... $ECHO_C" >&6
+# Check whether --enable-perm-items or --disable-perm-items was given.
+if test "${enable_perm_items+set}" = set; then
+  enableval="$enable_perm_items"
+
+			if test "z$enableval" != "zno" ; then
+					feature_permitems=1
+			else
+					feature_permitems=0
+			fi
+
+else
+   feature_permitems=0
+fi;
+
+
+if test $feature_permitems -ne 0; then
+
+cat >>confdefs.h <<\_ACEOF
+#define FEATURE_PERMITEM_ON 1
+_ACEOF
+
+	echo "$as_me:$LINENO: result: yeeeah (at your peril)" >&5
+echo "${ECHO_T}yeeeah (at your peril)" >&6
+else
+	echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+
+
+echo "$as_me:$LINENO: checking whether to use a magic ttl for permanent items" >&5
+echo $ECHO_N "checking whether to use a magic ttl for permanent items... $ECHO_C" >&6
+# Check whether --enable-perm-items-magic or --disable-perm-items-magic was given.
+if test "${enable_perm_items_magic+set}" = set; then
+  enableval="$enable_perm_items_magic"
+
+			if test "z$enableval" != "zno"; then
+				if test $feature_permitems -eq 0; then
+					{ { echo "$as_me:$LINENO: error: perm-items-magic
+						requires --enable-perm-items to make sure
+						you know what you're in for" >&5
+echo "$as_me: error: perm-items-magic
+						requires --enable-perm-items to make sure
+						you know what you're in for" >&2;}
+   { (exit 1); exit 1; }; }
+				fi
+
+				let "feature_permitems_magic=$enableval"
+				if test $feature_permitems_magic -eq 0; then
+					{ { echo "$as_me:$LINENO: error: a number is required,
+						but $enableval is not one, please come again" >&5
+echo "$as_me: error: a number is required,
+						but $enableval is not one, please come again" >&2;}
+   { (exit 1); exit 1; }; }
+				fi
+			fi
+
+else
+   let "feature_permitems_magic=0"
+fi;
+
+
+if test $feature_permitems_magic -ne 0; then
+
+cat >>confdefs.h <<_ACEOF
+#define FEATURE_PERMITEM_MAGICFORZERO $feature_permitems_magic
+_ACEOF
+
+	echo "$as_me:$LINENO: result: yes ($feature_permitems_magic)" >&5
+echo "${ECHO_T}yes ($feature_permitems_magic)" >&6
+else
+	echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
 
 
 LIBEVENT_URL=http://www.monkey.org/~provos/libevent/
@@ -6818,6 +6901,7 @@
 	   esac ||
 	   { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5
 echo "$as_me: error: cannot find input file: $ac_f" >&2;}
+
    { (exit 1); exit 1; }; };;
       esac
       ac_file_inputs="$ac_file_inputs $ac_f"
@@ -6949,6 +7033,13 @@
   [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
   *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
   esac
+
+  if test x"$ac_file" != x-; then
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
+    echo "$as_me: creating $ac_file" >&6;}
+    rm -f "$ac_file"
+  fi
+
 _ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF
diff -Naur memcached-1.2.5/configure.ac memcached-1.2.5-patched/configure.ac
--- memcached-1.2.5/configure.ac	2008-03-03 21:59:47.000000000 +0200
+++ memcached-1.2.5-patched/configure.ac	2008-03-11 16:12:34.000000000 +0200
@@ -36,6 +36,69 @@
        ]
 )
 
+dnl -------------------------------------------------------
+dnl enable permanent items (not subject to LRU replacement)
+
+AC_MSG_CHECKING([whether to enable permanent items])
+AC_ARG_ENABLE(perm-items,
+	AC_HELP_STRING([--enable-perm-items],
+		[Enable writing permanent items (not subject to LRU replacement) 
+			via negative ttl hack (default: no)]),
+		[
+			if test "z$enableval" != "zno" ; then
+					feature_permitems=1
+			else
+					feature_permitems=0
+			fi
+		], [ feature_permitems=0 ])
+
+
+if test $feature_permitems -ne 0; then
+	AC_DEFINE([FEATURE_PERMITEM_ON], 1, [switches on the permitems feature])
+	AC_MSG_RESULT(yeeeah (at your peril))
+else
+	AC_MSG_RESULT(no)
+fi
+
+dnl ---------------------------------------------------------
+dnl use a magic negative ttl value to denote 0 (never expires)
+
+
+AC_MSG_CHECKING([whether to use a magic ttl for permanent items])
+AC_ARG_ENABLE(perm-items-magic,
+	AC_HELP_STRING([--enable-perm-items-magic=number],
+		[Use a magic negative ttl for permanent items that should
+		never expire (equivalent to 0) for those whose clients
+		can't send '-0' ttl. Requires --enable-perm-items
+		(default: none)]),
+		[
+			if test "z$enableval" != "zno"; then
+				if test $feature_permitems -eq 0; then
+					AC_MSG_ERROR([perm-items-magic
+						requires --enable-perm-items to make sure
+						you know what you're in for], 1)
+				fi
+				
+				let "feature_permitems_magic=$enableval"
+				if test $feature_permitems_magic -eq 0; then
+					AC_MSG_ERROR([a number is required,
+						but $enableval is not one, please come again], 1)
+				fi
+			fi
+		], [ let "feature_permitems_magic=0" ])
+
+
+if test $feature_permitems_magic -ne 0; then
+	AC_DEFINE_UNQUOTED([FEATURE_PERMITEM_MAGICFORZERO], $feature_permitems_magic,
+		[magic negative ttl to use as a 0 equivalent for permanent items])
+	AC_MSG_RESULT(yes ($feature_permitems_magic))
+else
+	AC_MSG_RESULT(no)
+fi
+
+
+
+
 dnl ------------------------------------------------------
 dnl libevent detection.  swiped from Tor.  modified a bit.
 
diff -Naur memcached-1.2.5/items.c memcached-1.2.5-patched/items.c
--- memcached-1.2.5/items.c	2008-03-03 21:13:45.000000000 +0200
+++ memcached-1.2.5-patched/items.c	2008-03-11 16:12:37.000000000 +0200
@@ -189,6 +189,18 @@
 
 static void item_link_q(item *it) { /* item is the new head */
     item **head, **tail;
+
+#ifdef FEATURE_PERMITEM_ON
+	/* if this patch borks anything, this is what will have borked it ;) */
+	if (it->it_flags & ITEM_PERM)
+	{		
+			if(settings.verbose > 1)
+					fprintf(stderr, "feature-dbg> %p not linked into q\n", it);
+			return;
+	}
+#endif
+	
+
     /* always true, warns: assert(it->slabs_clsid <= LARGEST_ID); */
     assert((it->it_flags & ITEM_SLABBED) == 0);
 
@@ -207,6 +219,17 @@
 
 static void item_unlink_q(item *it) {
     item **head, **tail;
+
+#ifdef FEATURE_PERMITEM_ON
+	if (it->it_flags & ITEM_PERM)
+	{
+			if(settings.verbose > 1)
+					fprintf(stderr, "feature-dbg> %p not unlinked from q\n", it);
+			return;
+	}
+#endif
+
+
     /* always true, warns: assert(it->slabs_clsid <= LARGEST_ID); */
     head = &heads[it->slabs_clsid];
     tail = &tails[it->slabs_clsid];
diff -Naur memcached-1.2.5/memcached.c memcached-1.2.5-patched/memcached.c
--- memcached-1.2.5/memcached.c	2008-03-03 21:13:45.000000000 +0200
+++ memcached-1.2.5-patched/memcached.c	2008-03-11 16:12:39.000000000 +0200
@@ -348,6 +348,12 @@
             fprintf(stderr, "<%d server listening (udp)\n", sfd);
         else
             fprintf(stderr, "<%d new client connection\n", sfd);
+
+#ifdef FEATURE_PERMITEM_ON
+		if (init_state == conn_listening)
+				fprintf(stderr, "feature-dbg> permanent items feature enabled\n");
+#endif
+
     }
 
     c->sfd = sfd;
@@ -1371,6 +1377,10 @@
     int vlen, old_vlen;
     uint64_t req_cas_id;
     item *it, *old_it;
+#ifdef FEATURE_PERMITEM_ON
+	int isperm;
+#endif
+
 
     assert(c != NULL);
 
@@ -1385,7 +1395,26 @@
     nkey = tokens[KEY_TOKEN].length;
 
     flags = strtoul(tokens[2].value, NULL, 10);
-    exptime = strtol(tokens[3].value, NULL, 10);
+
+
+#ifdef FEATURE_PERMITEM_ON
+	/* XXX: are we guaranteed no leading whitespace here? */
+	isperm = (tokens[3].value[0]=='-');
+
+	/* abs(strtol(...)) should work, but strto* implementations are wonky
+	 *  in places (try strtol("foo", NULL, 10) ;]), so better safe than sorry
+	 */
+	exptime = strtol(&(tokens[3].value[isperm]), NULL, 10);
+#ifdef FEATURE_PERMITEM_MAGICFORZERO
+	exptime = isperm && exptime==abs(FEATURE_PERMITEM_MAGICFORZERO) ? 0 : exptime;
+#endif
+
+	if (isperm && settings.verbose > 1)
+		fprintf(stderr, "feature-dbg> processing perm item with exptime %d\n", exptime);
+	
+#else
+     exptime = strtol(tokens[3].value, NULL, 10);
+#endif
     vlen = strtol(tokens[4].value, NULL, 10);
 
     // does cas value exist?
@@ -1431,6 +1460,10 @@
     if(handle_cas)
       it->cas_id = req_cas_id;
 
+#ifdef FEATURE_PERMITEM_ON
+	it->it_flags |= isperm ? ITEM_PERM : 0;
+#endif	
+
     c->item = it;
     c->ritem = ITEM_data(it);
     c->rlbytes = it->nbytes;
diff -Naur memcached-1.2.5/memcached.h memcached-1.2.5-patched/memcached.h
--- memcached-1.2.5/memcached.h	2008-03-03 21:13:45.000000000 +0200
+++ memcached-1.2.5-patched/memcached.h	2008-03-11 16:12:39.000000000 +0200
@@ -12,6 +12,8 @@
 #include <event.h>
 #include <netdb.h>
 
+#include "config.h"
+
 #define DATA_BUFFER_SIZE 2048
 #define UDP_READ_BUFFER_SIZE 65536
 #define UDP_MAX_PAYLOAD_SIZE 1400
@@ -107,6 +109,11 @@
 /* temp */
 #define ITEM_SLABBED 4
 
+/* flag denoting a 'permanent' item, ie an item not subject to the LRU */
+#ifdef FEATURE_PERMITEM_ON
+	#define ITEM_PERM 8
+#endif
+
 typedef struct _stritem {
     struct _stritem *next;
     struct _stritem *prev;
