@@ -80,10 +80,8 @@ def persistent(name, **opts, &block)
8080 # @option opts [Boolean] :include_community whether to include the community ID in the cache key
8181 def write_collection ( name , value , **opts )
8282 check_collection ( value )
83-
8483 data = NamespacedEnvCache . normalize_collection ( value )
85- namespaced = construct_ns_key ( name , include_community : include_community ( opts ) )
86- @underlying . write ( namespaced , data , **opts )
84+ write_collection_data ( name , data , **opts )
8785 end
8886
8987 # Read an ActiveRecord collection from cache. Returns a basic collection of the records that were cached, with
@@ -148,11 +146,11 @@ def self.supports_cache_versioning?
148146 private
149147
150148 # Raises an error if a given collection is not cacheable
151- # @param collection [ActiveRecord::Relation] collection to check
152- def check_collection ( collection )
153- types = collection . map ( &:class ) . uniq
149+ # @param value [ActiveRecord::Relation] collection to check
150+ def check_collection ( value )
151+ types = value . map ( &:class ) . uniq
154152 if types . size > 1
155- raise TypeError , "Can't cache more than one type of object via write_collection "
153+ raise TypeError , "Can't cache more than one type of object"
156154 end
157155 end
158156
@@ -161,5 +159,14 @@ def construct_ns_key(key, include_community: true)
161159 c_id = RequestContext . community_id if include_community
162160 "#{ Rails . env } ://#{ [ c_id , key ] . compact . join ( '/' ) } "
163161 end
162+
163+ # Writes normalized collection data to the underlying cache
164+ # @param name [String] cache key name
165+ # @param data [[String, Integer, Integer, ...]] normalized collection data
166+ # @param opts [Hash] options hash - see #write_collection
167+ def write_collection_data ( name , data , **opts )
168+ namespaced = construct_ns_key ( name , include_community : include_community ( opts ) )
169+ @underlying . write ( namespaced , data , **opts )
170+ end
164171 end
165172end
0 commit comments