Class: HTTPDisk::CacheKey
- Inherits:
-
Object
- Object
- HTTPDisk::CacheKey
- Defined in:
- lib/httpdisk/cache_key.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#ignore_params ⇒ Object
readonly
Returns the value of attribute ignore_params.
Instance Method Summary collapse
-
#digest ⇒ Object
md5(key) (memoized).
-
#diskpath ⇒ Object
Relative path for this cache key based on hostdir & digest.
-
#initialize(env, ignore_params: []) ⇒ CacheKey
constructor
A new instance of CacheKey.
-
#key ⇒ Object
Cache key (memoized).
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(env, ignore_params: []) ⇒ CacheKey
Returns a new instance of CacheKey.
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 !/^https?$/.match?(env.url.scheme) raise InvalidUrl, "hostname required #{env.url.inspect}" if !env.url.host end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/httpdisk/cache_key.rb', line 7 def env @env end |
#ignore_params ⇒ Object (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
#digest ⇒ Object
md5(key) (memoized)
27 28 29 |
# File 'lib/httpdisk/cache_key.rb', line 27 def digest @digest ||= Digest::MD5.hexdigest(key) end |
#diskpath ⇒ Object
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 |
#key ⇒ Object
Cache key (memoized)
22 23 24 |
# File 'lib/httpdisk/cache_key.rb', line 22 def key @key ||= calculate_key end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/httpdisk/cache_key.rb', line 36 def to_s key end |
#url ⇒ Object
17 18 19 |
# File 'lib/httpdisk/cache_key.rb', line 17 def url env.url end |