Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8767

Show
Ignore:
Timestamp:
02/01/08 08:25:58 (7 months ago)
Author:
bitsweat
Message:

MemCacheStore#write and #delete return a boolean indicating whether the operation succeeded

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/cache/mem_cache_store.rb

    r8765 r8767  
    44  module Cache 
    55    class MemCacheStore < Store 
     6      module Response 
     7        STORED      = "STORED\r\n" 
     8        NOT_STORED  = "NOT_STORED\r\n" 
     9        EXISTS      = "EXISTS\r\n" 
     10        NOT_FOUND   = "NOT_FOUND\r\n" 
     11        DELETED     = "DELETED\r\n" 
     12      end 
     13 
    614      attr_reader :addresses 
    715 
     
    2230 
    2331      # Set key = value if key isn't already set. Pass :force => true 
    24       # to unconditionally set key = value. 
     32      # to unconditionally set key = value. Returns a boolean indicating 
     33      # whether the key was set. 
    2534      def write(key, value, options = {}) 
    2635        super 
    2736        method = options[:force] ? :set : :add 
    28         @data.send(method, key, value, expires_in(options), raw?(options)) 
     37        response = @data.send(method, key, value, expires_in(options), raw?(options)) 
     38        response == Response::STORED 
    2939      rescue MemCache::MemCacheError => e 
    3040        logger.error("MemCacheError (#{e}): #{e.message}") 
    31         nil 
     41        false 
    3242      end 
    3343 
    3444      def delete(key, options = nil) 
    3545        super 
    36         @data.delete(key, expires_in(options)) 
     46        response = @data.delete(key, expires_in(options)) 
     47        response == Response::DELETED 
    3748      rescue MemCache::MemCacheError => e 
    3849        logger.error("MemCacheError (#{e}): #{e.message}") 
    39         nil 
     50        false 
    4051      end 
    4152