class Latch::Storage::Memory

Overview

In-memory storage backend for testing purposes. Files are stored in a hash and are lost when the process exits. This is useful for testing without hitting the filesystem or network.

Latch.configure do |settings|
  settings.storages["cache"] = Latch::Storage::Memory.new
  settings.storages["store"] = Latch::Storage::Memory.new
end

Defined in:

latch/storage/memory.cr

Constructors

Instance Method Summary

Instance methods inherited from class Latch::Storage

delete(id : String) : Nil delete, exists?(id : String) : Bool exists?, move(io : IO, id : String, **options) : Nil
move(file : Latch::StoredFile, id : String, **options) : Nil
move
, open(id : String, **options) : IO open, upload(io : IO, id : String, **options) : Nil upload, url(id : String, **options) : String url

Constructor Detail

def self.new(base_url : String | Nil = nil) #

[View source]

Instance Method Detail

def base_url : String | Nil #

[View source]
def clear! : Nil #

Clears out the store.


[View source]
def delete(id : String) : Nil #

Deletes the file at the given location.


[View source]
def exists?(id : String) : Bool #

Returns whether a file exists at the given location.


[View source]
def open(id : String, **options) : IO #

Opens the file at the given location and returns an IO for reading.


[View source]
def size : Int32 #

Returns the number of stored files.


[View source]
def store : Hash(String, Bytes) #

[View source]
def upload(io : IO, id : String, **options) : Nil #

Uploads an IO to the given location (id) in the storage.


[View source]
def url(id : String, **options) : String #

Returns the URL for accessing the file at the given location.


[View source]