Sha256: 758baf9a09f7ca1d4a3917415814b1df72c6d6003c082a915ca15fc00d60f1e9

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

##
# This module provides a simple key/value cache for storing computation results
module BasicCache
  # Check if we're using a version if Ruby that supports caller_locations
  NEW_CALL = Kernel.respond_to? 'caller_locations'

  class << self
    ##
    # Insert a helper .new() method for creating a new Cache object

    def new(*args)
      self::Cache.new(*args)
    end

    ##
    # Provide a helper method to get the calling function name
    # If available, caller_locations is available and is much faster.
    # If not, fall back to caller
    # These methods return the name of the calling function 2 levels up
    # This allows them to return the name of whatever called Cache.cache()

    def caller_name
      NEW_CALL ? caller_locations(2, 1).first.label : caller[1][/`([^']*)'/, 1]
    end
  end
end

require 'stores/store'
require 'caches/cache'
require 'caches/timecache'
require 'methodcacher'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basiccache-0.1.0 lib/basiccache.rb