GitHub PullRequestReviewCommentEvent at 2014-01-07 18:28:29
Repository: rails_cache_adapters
Actor: dylanahsmith
Payload: {"comment":{"url":"https://api.github.com/repos/Shopify/rails_cache_adapters/pulls/comments/8701485","id":8701485,"diff_hunk":"@@ -0,0 +1,152 @@\n+# file havily based out off https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/cache/mem_cache_store.rb\n+require 'digest/md5'\n+\n+module ActiveSupport\n+  module Cache\n+    # A cache store implementation which stores data in Memcached:\n+    # http://memcached.org/\n+    #\n+    # MemcachedStore uses memcached gem as backend to connect to Memcached server.\n+    #\n+    # MemcachedStore implements the Strategy::LocalCache strategy which implements\n+    # an in-memory cache inside of a block.\n+    class MemcachedStore < Store\n+      FATAL_EXCEPTIONS = [ Memcached::ABadKeyWasProvidedOrCharactersOutOfRange,\n+        Memcached::AKeyLengthOfZeroWasProvided,\n+        Memcached::ConnectionBindFailure,\n+        Memcached::ConnectionDataDoesNotExist,\n+        Memcached::ConnectionFailure,\n+        Memcached::ConnectionSocketCreateFailure,\n+        Memcached::CouldNotOpenUnixSocket,\n+        Memcached::NoServersDefined,\n+        Memcached::TheHostTransportProtocolDoesNotMatchThatOfTheClient\n+      ]\n+\n+      if defined?(::Rails) && ::Rails.env.test?\n+        NONFATAL_EXCEPTIONS = []\n+      else\n+        NONFATAL_EXCEPTIONS = Memcached::EXCEPTIONS - FATAL_EXCEPTIONS\n+      end\n+\n+      ESCAPE_KEY_CHARS = /[\\x00-\\x20%\\x7F-\\xFF]/n\n+\n+      def self.build_memcached(*addresses)\n+        addresses = addresses.flatten\n+        options = addresses.extract_options!\n+        addresses = [\"localhost:11211\"] if addresses.empty?\n+        Memcached::Rails.new(addresses, options)\n+      end\n+\n+      def initialize(*addresses)\n+        addresses = addresses.flatten\n+        options = addresses.extract_options!\n+        super(options)\n+\n+        if addresses.first.respond_to?(:get)\n+          @data = addresses.first\n+        else\n+          mem_cache_options = options.dup\n+          UNIVERSAL_OPTIONS.each{|name| mem_cache_options.delete(name)}\n+          @data = self.class.build_memcached(*(addresses + [mem_cache_options]))\n+        end\n+\n+        extend Strategy::LocalCache\n+      end\n+\n+      def read_multi(*names)\n+        options = names.extract_options!\n+        options = merged_options(options)\n+        keys_to_names = Hash[names.map{|name| [escape_key(namespaced_key(name, options)), name]}]\n+        raw_values = @data.get_multi(keys_to_names.keys, :raw => true)\n+        values = {}\n+        raw_values.each do |key, value|\n+          entry = deserialize_entry(value)\n+          values[keys_to_names[key]] = entry.value unless entry.expired?\n+        end\n+        values\n+      end\n+\n+      def increment(name, amount = 1, options = nil) # :nodoc:\n+        options = merged_options(options)\n+        instrument(:increment, name, :amount => amount) do\n+          @data.incr(escape_key(namespaced_key(name, options)), amount)\n+        end\n+      rescue *NONFATAL_EXCEPTIONS => e\n+        @data.log_exception(e)\n+        nil\n+      end\n+\n+      def decrement(name, amount = 1, options = nil) # :nodoc:\n+        options = merged_options(options)\n+        instrument(:decrement, name, :amount => amount) do\n+          @data.decr(escape_key(namespaced_key(name, options)), amount)\n+        end\n+      rescue *NONFATAL_EXCEPTIONS => e\n+        @data.log_exception(e)","path":"lib/active_support/cache/memcached_store.rb","position":85,"original_position":85,"commit_id":"765299be2a4c12b881124217287fca5f063e7993","original_commit_id":"765299be2a4c12b881124217287fca5f063e7993","user":{"login":"dylanahsmith","id":954402,"avatar_url":"https://gravatar.com/avatar/d6af3d9442783aa00ef1e5d7772f997d?d=https%3A%2F%2Fidenticons.github.com%2F95f1d47eb81295ff9866b9f7291894c1.png&r=x","gravatar_id":"d6af3d9442783aa00ef1e5d7772f997d","url":"https://api.github.com/users/dylanahsmith","html_url":"https://github.com/dylanahsmith","followers_url":"https://api.github.com/users/dylanahsmith/followers","following_url":"https://api.github.com/users/dylanahsmith/following{/other_user}","gists_url":"https://api.github.com/users/dylanahsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/dylanahsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylanahsmith/subscriptions","organizations_url":"https://api.github.com/users/dylanahsmith/orgs","repos_url":"https://api.github.com/users/dylanahsmith/repos","events_url":"https://api.github.com/users/dylanahsmith/events{/privacy}","received_events_url":"https://api.github.com/users/dylanahsmith/received_events","type":"User","site_admin":false},"body":"nevermind","created_at":"2014-01-07T18:28:29Z","updated_at":"2014-01-07T18:28:29Z","html_url":"https://github.com/Shopify/rails_cache_adapters/pull/4#discussion_r8701485","pull_request_url":"https://api.github.com/repos/Shopify/rails_cache_adapters/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/Shopify/rails_cache_adapters/pulls/comments/8701485"},"html":{"href":"https://github.com/Shopify/rails_cache_adapters/pull/4#discussion_r8701485"},"pull_request":{"href":"https://api.github.com/repos/Shopify/rails_cache_adapters/pulls/4"}}}}