An open API service indexing awesome lists of open source software.

https://github.com/malvads/easycache

easy ruby gem for caching key-value data in mem (used in production at redborder)
https://github.com/malvads/easycache

cache caching easycache easycaching gem key-value key-value-storage key-value-store ruby ruby-gem

Last synced: 11 months ago
JSON representation

easy ruby gem for caching key-value data in mem (used in production at redborder)

Awesome Lists containing this project

README

          

# EasyCache

[![Gem Version](https://badge.fury.io/rb/easycache.svg)](https://badge.fury.io/rb/easycache)
![License](https://img.shields.io/badge/license-AGPL%203.0-blue.svg)
[![Lint](https://github.com/malvads/easy-cache/actions/workflows/lint.yml/badge.svg)](https://github.com/malvads/easy-cache/actions/workflows/lint.yml)
[![Tests](https://github.com/malvads/easycache/actions/workflows/tests.yml/badge.svg)](https://github.com/malvads/easycache/actions/workflows/tests.yml)
[![Build](https://github.com/malvads/easycache/actions/workflows/build.yml/badge.svg)](https://github.com/malvads/easycache/actions/workflows/build.yml)

Maybe not the best caching system, but its a caching system :)

EasyCache is an in-memory cache system for Ruby designed for situations where you don't want to set up Redis or Memcached but still need a simple solution for caching key-value data in the `process` memory.

## Install

```
gem install easycache
```

## Usage

To use EasyCache in your Ruby project, require the library and include it in your code:

```ruby
require 'easycache'

cache = EasyCache.new
```

## Storing data

```ruby
key = "my_key"
cache_ttl = 3600
store_in_mem = true
data = cache.fetch(cache_key, cache_ttl, store_in_mem) do
my_http_get
end
```

Now data is in-mem for the next 3600 second (store_in_mem variable is important for storing data first time).

## Getting data

If i want to get the data stored in mem i do

```ruby
data = cache.fetch("my_key")
```

or i can also re-call the same function

```ruby
data = cache.fetch("my_key", cache_ttl, store_in_mem) do
my_http_get
end
```

because the data is already cached, so it will not call the block, it will return the cached data instead.

This will output the cached data, remember that cached data is stored in mem for only 3600 seconds

## Examples

You can search for examples in `examples` folder for caching http requests and responses using EasyCache

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/malvads/easycache .