Sha256: 99a1254e3ad0beb4127ff05b7b71dca81e3e066c8078ecb678d1b9f5b6d0cef7

Contents?: true

Size: 832 Bytes

Versions: 4

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

module Waylon
  # Used for working with the Moneta store for caching
  module Cache
    DefaultStorage = Moneta.new(
      :Redis,
      url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/1"
    )

    def self.clear
      storage.clear
    end

    def self.delete(key)
      storage.delete(key)
    end

    def self.key?(name)
      storage.key?(name)
    end

    def self.load(key, expires: nil)
      expires ? storage.load(key, expires: expires) : storage.load(key)
    end

    def self.store(key, value, expires: nil)
      if expires
        storage.store(key, value, expires: expires)
      else
        storage.store(key, value)
      end
    end

    def self.storage
      @storage ||= DefaultStorage
    end

    def self.storage=(storage)
      @storage = storage
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
waylon-core-0.2.4 lib/waylon/cache.rb
waylon-core-0.2.3 lib/waylon/cache.rb
waylon-core-0.2.2 lib/waylon/cache.rb
waylon-core-0.2.1 lib/waylon/cache.rb