garner 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/LICENSE.md +1 -1
  2. data/README.md +116 -135
  3. data/lib/garner/cache/binding.rb +58 -0
  4. data/lib/garner/cache/context.rb +27 -0
  5. data/lib/garner/cache/identity.rb +45 -0
  6. data/lib/garner/cache.rb +41 -0
  7. data/lib/garner/config.rb +46 -15
  8. data/lib/garner/mixins/mongoid/document.rb +75 -0
  9. data/lib/garner/mixins/mongoid/identity.rb +106 -0
  10. data/lib/garner/mixins/mongoid.rb +4 -0
  11. data/lib/garner/mixins/rack.rb +45 -0
  12. data/lib/garner/strategies/binding/invalidation/base.rb +26 -0
  13. data/lib/garner/strategies/binding/invalidation/touch.rb +27 -0
  14. data/lib/garner/strategies/binding/key/base.rb +19 -0
  15. data/lib/garner/strategies/binding/key/cache_key.rb +19 -0
  16. data/lib/garner/strategies/binding/key/safe_cache_key.rb +33 -0
  17. data/lib/garner/strategies/context/key/base.rb +21 -0
  18. data/lib/garner/strategies/context/key/caller.rb +83 -0
  19. data/lib/garner/strategies/context/key/jsonp.rb +30 -0
  20. data/lib/garner/strategies/context/key/request_get.rb +30 -0
  21. data/lib/garner/strategies/context/key/request_path.rb +28 -0
  22. data/lib/garner/strategies/context/key/request_post.rb +30 -0
  23. data/lib/garner/version.rb +1 -1
  24. data/lib/garner.rb +29 -26
  25. metadata +122 -22
  26. data/lib/garner/cache/object_identity.rb +0 -249
  27. data/lib/garner/middleware/base.rb +0 -47
  28. data/lib/garner/middleware/cache/bust.rb +0 -20
  29. data/lib/garner/mixins/grape_cache.rb +0 -111
  30. data/lib/garner/mixins/mongoid_document.rb +0 -58
  31. data/lib/garner/strategies/cache/expiration_strategy.rb +0 -16
  32. data/lib/garner/strategies/etags/grape_strategy.rb +0 -32
  33. data/lib/garner/strategies/etags/marshal_strategy.rb +0 -16
  34. data/lib/garner/strategies/keys/caller_strategy.rb +0 -38
  35. data/lib/garner/strategies/keys/jsonp_strategy.rb +0 -24
  36. data/lib/garner/strategies/keys/key_strategy.rb +0 -21
  37. data/lib/garner/strategies/keys/request_get_strategy.rb +0 -24
  38. data/lib/garner/strategies/keys/request_path_strategy.rb +0 -21
  39. data/lib/garner/strategies/keys/request_post_strategy.rb +0 -24
  40. data/lib/garner/strategies/keys/version_strategy.rb +0 -29
@@ -1,16 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Cache
4
- # Injects an expires_in value from the global configuration.
5
- module Expiration
6
- class << self
7
- def apply(current, options = {})
8
- rc = current ? current.dup : {}
9
- rc[:expires_in] = Garner.config.expires_in if Garner.config.expires_in && ! current[:expires_in]
10
- rc
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,32 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module ETags
4
- module Grape
5
- class << self
6
- # @abstract
7
- # Serialize in a way such that the ETag matches that which would
8
- # be returned by Grape + Rack::ETag at response time.
9
- def apply(object)
10
- serialization = encode_json(object || "")
11
- %("#{Digest::MD5.hexdigest(serialization)}")
12
- end
13
-
14
- # See https://github.com/intridea/grape/blob/master/lib/grape/middleware/base.rb
15
- def encode_json(object)
16
- return object if object.is_a?(String)
17
-
18
- if object.respond_to? :serializable_hash
19
- MultiJson.dump(object.serializable_hash)
20
- elsif object.kind_of?(Array) && !object.map {|o| o.respond_to? :serializable_hash }.include?(false)
21
- MultiJson.dump(object.map {|o| o.serializable_hash })
22
- elsif object.respond_to? :to_json
23
- object.to_json
24
- else
25
- MultiJson.dump(object)
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,16 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module ETags
4
- module Marshal
5
- class << self
6
- # @abstract
7
- # Serialize using Ruby's Marshal.dump.
8
- def apply(object)
9
- serialization = ::Marshal.dump(object || "")
10
- %("#{Digest::MD5.hexdigest(serialization)}")
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,38 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Injects the caller's location into the key.
5
- module Caller
6
- class << self
7
-
8
- def field
9
- :caller
10
- end
11
-
12
- def apply(key, context = {})
13
- rc = key ? key.dup : {}
14
- if context.keys.include?(field)
15
- rc[field] = context[field]
16
- return rc
17
- end
18
-
19
- if caller
20
- caller.each do |line|
21
- next unless line
22
- split = line.split(":")
23
- next unless split && split.length >= 2
24
- path = (Pathname.new(split[0]).realpath.to_s rescue nil)
25
- next if (! path) || path.empty? || path.include?("lib/garner")
26
- next unless path.include?("/app/") || path.include?("/spec/")
27
- rc[field] = "#{path}:#{split[1]}"
28
- break
29
- end
30
- end
31
-
32
- rc
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,24 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Strips JSONP parameters from the key.
5
- module Jsonp
6
- class << self
7
-
8
- def field
9
- :params
10
- end
11
-
12
- def apply(key, context = {})
13
- key = key ? key.dup : {}
14
- return unless key[field]
15
- key[field].delete("callback")
16
- key[field].delete("_")
17
- key
18
- end
19
-
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,21 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Inject a key into the cache key.
5
- module Key
6
- class << self
7
-
8
- def field
9
- :key
10
- end
11
-
12
- def apply(key, context = {})
13
- key = key ? key.dup : {}
14
- key[field] = context[:key] if context && context.has_key?(:key)
15
- key
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,24 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Inject the request GET parameters into the key.
5
- module RequestGet
6
- class << self
7
-
8
- def field
9
- :params
10
- end
11
-
12
- def apply(key, context = {})
13
- key = key ? key.dup : {}
14
- if context && (request = context[:request]) && [ "GET", "HEAD" ].include?(request.request_method)
15
- key[field] = context[:request].GET.dup
16
- end
17
- key
18
- end
19
-
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,21 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Inject the request path into the key.
5
- module RequestPath
6
- class << self
7
-
8
- def field
9
- :path
10
- end
11
-
12
- def apply(key, context = {})
13
- key = key ? key.dup : {}
14
- key[field] = context[:request].path if context && context[:request] && context[:request].respond_to?(:path)
15
- key
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,24 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Inject the request POST parameters into the key.
5
- module RequestPost
6
- class << self
7
-
8
- def field
9
- :params
10
- end
11
-
12
- def apply(key, context = {})
13
- key = key ? key.dup : {}
14
- if context && (request = context[:request]) && request.request_method == "POST"
15
- key[field] = request.POST.dup
16
- end
17
- key
18
- end
19
-
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,29 +0,0 @@
1
- module Garner
2
- module Strategies
3
- module Keys
4
- # Inject the request path into the key.
5
- module Version
6
- class << self
7
-
8
- def field
9
- :version
10
- end
11
-
12
- def default_version
13
- nil
14
- end
15
-
16
- def apply(key, context = {})
17
- key = key ? key.dup : {}
18
- if context && context[:version]
19
- key[:version] = context[:version]
20
- elsif default_version
21
- key[:version] = default_version
22
- end
23
- key
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end