@@ -89,6 +89,11 @@ def write_entry(key, entry, **options)
8989 end
9090
9191 # Write entry using simple hash-based file structure
92+ #
93+ # @param key [String] The cache key
94+ # @param entry [ActiveSupport::Cache::Entry] The cache entry
95+ # @param options [Hash] Options (expiration is ignored)
96+ # @return [Boolean] Returns true on success
9297 def write_entry_simple ( key , entry , **options )
9398 hash = hash_key ( key )
9499
@@ -102,12 +107,17 @@ def write_entry_simple(key, entry, **options)
102107 end
103108
104109 # Write entry using subdirectory structure
110+ #
111+ # @param key [String] The cache key
112+ # @param entry [ActiveSupport::Cache::Entry] The cache entry
113+ # @param options [Hash] Options (expiration is ignored)
114+ # @return [Boolean] Returns true on success
105115 def write_entry_with_subdirectories ( key , entry , **options )
106116 chunks = key . to_s . split ( @subdirectory_delimiter )
107117 current_dir = @cache_path
108118
109119 # Create subdirectories for each chunk
110- chunks . each_with_index do |chunk , index |
120+ chunks . each do |chunk |
111121 chunk_hash = hash_chunk ( chunk )
112122 current_dir = File . join ( current_dir , chunk_hash )
113123 FileUtils . mkdir_p ( current_dir )
@@ -159,20 +169,17 @@ def delete_entry_simple(key, **options)
159169 end
160170
161171 # Delete entry using subdirectory structure
172+ #
173+ # @param key [String] The cache key
174+ # @param options [Hash] Options (unused)
175+ # @return [Boolean] Returns true if the entry was deleted
162176 def delete_entry_with_subdirectories ( key , **options )
163177 value_file = value_path_for_key ( key )
164178
165179 return false unless File . exist? ( value_file )
166180
167181 # Delete only the deepest directory containing this specific entry
168- chunks = key . to_s . split ( @subdirectory_delimiter )
169-
170- # Build the full path to the final directory
171- current_dir = @cache_path
172- chunks . each do |chunk |
173- chunk_hash = hash_chunk ( chunk )
174- current_dir = File . join ( current_dir , chunk_hash )
175- end
182+ current_dir = subdirectory_path_for_key ( key )
176183
177184 begin
178185 # Delete the final directory (containing _key_chunk and value)
@@ -221,19 +228,27 @@ def value_path(hash)
221228 # @return [String] The full path to the value file
222229 def value_path_for_key ( key )
223230 if @subdirectory_delimiter
224- chunks = key . to_s . split ( @subdirectory_delimiter )
225- current_dir = @cache_path
226-
227- chunks . each do |chunk |
228- chunk_hash = hash_chunk ( chunk )
229- current_dir = File . join ( current_dir , chunk_hash )
230- end
231-
232- File . join ( current_dir , "value" )
231+ File . join ( subdirectory_path_for_key ( key ) , "value" )
233232 else
234233 value_path ( hash_key ( key ) )
235234 end
236235 end
236+
237+ # Get the subdirectory path for a given key
238+ #
239+ # @param key [String] The cache key
240+ # @return [String] The full path to the subdirectory for this key
241+ def subdirectory_path_for_key ( key )
242+ chunks = key . to_s . split ( @subdirectory_delimiter )
243+ current_dir = @cache_path
244+
245+ chunks . each do |chunk |
246+ chunk_hash = hash_chunk ( chunk )
247+ current_dir = File . join ( current_dir , chunk_hash )
248+ end
249+
250+ current_dir
251+ end
237252 end
238253 end
239254end
0 commit comments