Socket
Book a DemoInstallSign in
Socket

easy_cache

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy_cache

bundlerRubygems
Version
0.0.1
Version published
Maintainers
1
Created
Source

EasyCache is a way to easily cache method calls to a readable YAML file.

Internally it uses the gemmy library I made.

Specifically, the PersistedHash (which syncs a hash's state to YAML file) is extended with a get_or_set(key, &blk) method where the block result gets cached as key.

The return value of get_or_set is the block result. So it can easily be placed as a wrapper around any synchronous method:


require 'easy_cache'
                # The ~/gemmy path will be automatically created
                # However the cache path can be overridden with:
                # ENV["GEMMY_CACHE_PATH"]

my_method_cad(arg)
  my_method_cache.get_or_set(arg) do
    "#{arg} result is saved" 
  end
end

def my_method(arg)
  my_method_cache.get_or_set(arg) do
    "#{arg} result is saved"
  end
end

There are other methods in the API, too.

  • #clear
  • #set_state(hash)
  • #get(*nested_keys)
  • #set(*nested_keys, val)
  • #data (the entire state)

Note that [] and []= only interact with the in-memory hash. They don't touch the YAML file.

FAQs

Package last updated on 22 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.