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)
- Host: GitHub
- URL: https://github.com/malvads/easycache
- Owner: malvads
- License: agpl-3.0
- Created: 2024-02-27T13:31:49.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-29T12:51:32.000Z (about 2 years ago)
- Last Synced: 2025-03-29T12:46:56.905Z (12 months ago)
- Topics: cache, caching, easycache, easycaching, gem, key-value, key-value-storage, key-value-store, ruby, ruby-gem
- Language: Ruby
- Homepage: https://rubygems.org/gems/easycache/
- Size: 42 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EasyCache
[](https://badge.fury.io/rb/easycache)

[](https://github.com/malvads/easy-cache/actions/workflows/lint.yml)
[](https://github.com/malvads/easycache/actions/workflows/tests.yml)
[](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 .