Sha256: f76e1bffdfda393a6659b8bf6707ab1cddd01803e150f4c2525d4aebf782d9dd

Contents?: true

Size: 892 Bytes

Versions: 10

Compression:

Stored size: 892 Bytes

Contents

require 'memcache'
require 'digest/md5'
module NBS  
  module MemcachedMemoize
    def remember(name)
     
     original_method = instance_method(name)
     define_method(name) do |*args|
      
      if defined?(KEYSTORE)
       key = args.collect {|c| c.to_s }.join("_").gsub(" ","_")
       key+=name.to_s
       key = Digest::MD5.hexdigest(key)
       puts key
       if KEYSTORE.get(key)!=nil
         puts "it was memorized" 
         Marshal.restore(KEYSTORE.get(key))
       else
         puts "it had to be memorized"  
         bound_method = original_method.bind(self)
         #puts Marshal.dump(bound_method.call(*args))
         KEYSTORE.set(key,Marshal.dump(bound_method.call(*args)))
         return Marshal.restore(KEYSTORE.get(key))
       end
     else
       bound_method = original_method.bind(self)
       bound_method.call(*args)
     end
     end
    end   
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
next-big-sound-0.8.2 lib/next-big-sound/memoize.rb
next-big-sound-0.8.1 lib/next-big-sound/memoize.rb
next-big-sound-0.8.0 lib/next-big-sound/memoize.rb
next-big-sound-0.7.0 lib/next-big-sound/memoize.rb
next-big-sound-0.6.1 lib/next-big-sound/memoize.rb
next-big-sound-0.5.0 lib/memoize.rb
next-big-sound-0.4.4 lib/memoize.rb
next-big-sound-0.4.3 lib/memoize.rb
next-big-sound-0.4.2 lib/memoize.rb
next-big-sound-0.4.1 lib/memoize.rb