@@ -407,13 +407,18 @@ def paired(cls, left, right=None, **connection_args):
407407 return cls ([":" .join (map (str , left )), ":" .join (map (str , right ))],
408408 ** connection_args )
409409
410+ def _cached (self , dbname , coll , index ):
411+ """Test if `index` is cached.
412+ """
413+ cache = self .__index_cache
414+ now = datetime .datetime .utcnow ()
415+ return (dbname in cache and
416+ coll in cache [dbname ] and
417+ index in cache [dbname ][coll ] and
418+ now < cache [dbname ][coll ][index ])
419+
410420 def _cache_index (self , database , collection , index , ttl ):
411421 """Add an index to the index cache for ensure_index operations.
412-
413- Return ``True`` if the index has been newly cached or if the index had
414- expired and is being re-cached.
415-
416- Return ``False`` if the index exists and is valid.
417422 """
418423 now = datetime .datetime .utcnow ()
419424 expire = datetime .timedelta (seconds = ttl ) + now
@@ -422,19 +427,13 @@ def _cache_index(self, database, collection, index, ttl):
422427 self .__index_cache [database ] = {}
423428 self .__index_cache [database ][collection ] = {}
424429 self .__index_cache [database ][collection ][index ] = expire
425- return True
426430
427- if collection not in self .__index_cache [database ]:
431+ elif collection not in self .__index_cache [database ]:
428432 self .__index_cache [database ][collection ] = {}
429433 self .__index_cache [database ][collection ][index ] = expire
430- return True
431434
432- if index in self .__index_cache [database ][collection ]:
433- if now < self .__index_cache [database ][collection ][index ]:
434- return False
435-
436- self .__index_cache [database ][collection ][index ] = expire
437- return True
435+ else :
436+ self .__index_cache [database ][collection ][index ] = expire
438437
439438 def _purge_index (self , database_name ,
440439 collection_name = None , index_name = None ):
0 commit comments