Class: HTTPDisk::CacheKey

Inherits:
Object
  • Object
show all
Defined in:
lib/httpdisk/cache_key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, ignore_params: []) ⇒ CacheKey

Returns a new instance of CacheKey.

Raises:



9
10
11
12
13
14
15
# File 'lib/httpdisk/cache_key.rb', line 9

def initialize(env, ignore_params: [])
  @env, @ignore_params = env, ignore_params

  # sanity checks
  raise InvalidUrl, "http/https required #{env.url.inspect}" if env.url.scheme !~ /^https?$/
  raise InvalidUrl, "hostname required #{env.url.inspect}" if !env.url.host
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/httpdisk/cache_key.rb', line 7

def env
  @env
end

#ignore_paramsObject (readonly)

Returns the value of attribute ignore_params.



7
8
9
# File 'lib/httpdisk/cache_key.rb', line 7

def ignore_params
  @ignore_params
end

Instance Method Details

#digestObject

md5(key) (memoized)



27
28
29
# File 'lib/httpdisk/cache_key.rb', line 27

def digest
  @digest ||= Digest::MD5.hexdigest(key)
end

#diskpathObject

Relative path for this cache key based on hostdir & digest.



32
33
34
# File 'lib/httpdisk/cache_key.rb', line 32

def diskpath
  @diskpath ||= File.join(hostdir, digest[0, 3], digest[3..])
end

#keyObject

Cache key (memoized)



22
23
24
# File 'lib/httpdisk/cache_key.rb', line 22

def key
  @key ||= calculate_key
end

#to_sObject



36
37
38
# File 'lib/httpdisk/cache_key.rb', line 36

def to_s
  key
end

#urlObject



17
18
19
# File 'lib/httpdisk/cache_key.rb', line 17

def url
  env.url
end