@@ -2,14 +2,19 @@ module Graphiti
22 class ResourceProxy
33 include Enumerable
44
5- attr_reader :resource , :query , :scope , :payload , :cache_expires_in , :cache
5+ attr_reader :resource , :query , :scope , :payload , :cache_expires_in , :cache , :cache_tag
66
7- def initialize ( resource , scope , query ,
7+ def initialize (
8+ resource ,
9+ scope ,
10+ query ,
811 payload : nil ,
912 single : false ,
1013 raise_on_missing : false ,
1114 cache : nil ,
12- cache_expires_in : nil )
15+ cache_expires_in : nil ,
16+ cache_tag : nil
17+ )
1318
1419 @resource = resource
1520 @scope = scope
@@ -19,6 +24,7 @@ def initialize(resource, scope, query,
1924 @raise_on_missing = raise_on_missing
2025 @cache = cache
2126 @cache_expires_in = cache_expires_in
27+ @cache_tag = cache_tag
2228 end
2329
2430 def cache?
@@ -207,12 +213,30 @@ def etag
207213 "W/#{ ActiveSupport ::Digest . hexdigest ( cache_key_with_version . to_s ) } "
208214 end
209215
216+ def resource_cache_tag
217+ return unless @cache_tag . present? && @resource . respond_to? ( @cache_tag )
218+
219+ @resource . try ( @cache_tag )
220+ end
221+
210222 def cache_key
211- ActiveSupport ::Cache . expand_cache_key ( [ @scope . cache_key , @query . cache_key ] )
223+ ActiveSupport ::Cache . expand_cache_key (
224+ [
225+ @scope . cache_key ,
226+ @query . cache_key ,
227+ resource_cache_tag
228+ ] . compact_blank
229+ )
212230 end
213231
214232 def cache_key_with_version
215- ActiveSupport ::Cache . expand_cache_key ( [ @scope . cache_key_with_version , @query . cache_key ] )
233+ ActiveSupport ::Cache . expand_cache_key (
234+ [
235+ @scope . cache_key_with_version ,
236+ @query . cache_key ,
237+ resource_cache_tag
238+ ] . compact_blank
239+ )
216240 end
217241
218242 private
0 commit comments