Sha256: f7f185ae29f917079c0b638433c9a25cfacd24086254ffcfe6e09b71e69b53ee

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 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 get_caller
      NEW_CALL ? caller_locations(2, 1).first.label : caller[1][/`([^']*)'/, 1]
    end
  end
end

require 'caches/cache'
require 'caches/timecache'
require 'methodcacher'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
basiccache-0.0.25 lib/basiccache.rb
basiccache-0.0.24 lib/basiccache.rb
basiccache-0.0.22 lib/basiccache.rb