class Sprockets::Cache::FileStore

def set(key, value)

Experimental RBS support (using type sampling data from the type_fusion project).

def set: (String key, (Hash | String) value) -> (Hash | String)

This signature was generated using 2 samples from 1 application.

Returns Object value.

value - Object value.
key - String cache key.

This API should not be used directly, but via the Cache wrapper API.

Public: Set a key and value in the cache.
def set(key, value)
  path = File.join(@root, "#{key}.cache")
  # Ensure directory exists
  FileUtils.mkdir_p File.dirname(path)
  # Check if cache exists before writing
  exists = File.exist?(path)
  # Serialize value
  marshaled = Marshal.dump(value)
  # Compress if larger than 4KB
  if marshaled.bytesize > 4 * 1024
    deflater = Zlib::Deflate.new(
      Zlib::BEST_COMPRESSION,
      Zlib::MAX_WBITS,
      Zlib::MAX_MEM_LEVEL,
      Zlib::DEFAULT_STRATEGY
    )
    deflater << marshaled
    raw = deflater.finish
  else
    raw = marshaled
  end
  # Write data
  PathUtils.atomic_write(path) do |f|
    f.write(raw)
    @size = size + f.size unless exists
  end
  # GC if necessary
  gc! if size > @max_size
  value
end