Index: /trunk/Nebulous-Server/Build.PL
===================================================================
--- /trunk/Nebulous-Server/Build.PL	(revision 24346)
+++ /trunk/Nebulous-Server/Build.PL	(revision 24347)
@@ -10,4 +10,5 @@
     requires            => {
         'Apache2::Const'        => 0,
+        'Cache::Memcached::Managed' => '0.20',
         'Class::Accessor::Fast' => 0,
         'Config::YAML'          => '1.42',
Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 24346)
+++ /trunk/Nebulous-Server/Changes	(revision 24347)
@@ -2,4 +2,5 @@
 
 0.17
+    - add basic valid key caching via memcached 
     - add params checking to Nebulous::Key::parse_neb_key()
     - restrict creation/modification/remove of xattrs to the user.* namespace
Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24346)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24347)
@@ -27,6 +27,7 @@
 use Params::Validate qw( validate validate_pos SCALAR SCALARREF UNDEF BOOLEAN );
 use URI::file;
-
-__PACKAGE__->mk_accessors(qw( log sql config ));
+use Cache::Memcached::Managed;
+
+__PACKAGE__->mk_accessors(qw( log sql config cache ));
 
 use constant SUBPATH_DEPTH  => 2;
@@ -62,5 +63,5 @@
     $self->sql($sql);
     $self->config($config);
-
+    $self->cache(Cache::Memcached::Managed->new($config->memcached));
     $log->debug( "leaving" );
 
@@ -1577,4 +1578,7 @@
             # remove it too
             if ( $instances == 1 ) {
+                # remove key from cache
+                $self->cache->delete($key->path);
+
                 # we just removed the last instance
                 my $query = $db->prepare_cached( $sql->delete_object );
@@ -1895,4 +1899,14 @@
     $log->logdie("$@") if $@;
 
+    # check cache first
+    my $cached = $self->cache->get($key->path);
+    if (defined $cached) {
+        $log->debug( "key $key found in cache" );
+        $log->debug( "leaving" );
+        return 1;
+    } else {
+        $log->debug( "key $key not found in cache" );
+    }
+
     my $db  = $self->db($key);
 
@@ -1911,10 +1925,10 @@
 
     if (defined $ext_id) {
-        $log->debug( "key is valid" );
+        $log->debug( "key found in db" );
         $log->debug( "leaving" );
         return 1;
     } 
 
-    $log->debug( "key not found" );
+    $log->debug( "key not found in db" );
     $log->debug( "leaving" );
 
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/Config.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/Config.pm	(revision 24346)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/Config.pm	(revision 24347)
@@ -49,4 +49,5 @@
     dbuser      => { type => SCALAR, optional => 1 },
     dbpasswd    => { type => SCALAR, optional => 1 },
+    memcached   => { type => SCALAR, default => '127.0.0.1:11311' },
 };
 
