Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/majioa/redisize
Make json record cacheable to redis via various adapters like Resque, Sidekiq, etc
https://github.com/majioa/redisize
Last synced: 1 day ago
JSON representation
Make json record cacheable to redis via various adapters like Resque, Sidekiq, etc
- Host: GitHub
- URL: https://github.com/majioa/redisize
- Owner: majioa
- License: mit
- Created: 2022-07-26T11:02:43.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-31T19:51:49.000Z (about 1 year ago)
- Last Synced: 2024-11-23T00:19:17.867Z (2 months ago)
- Language: Ruby
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Redisize
The gem allows to use asynchonous way to cache or just store in redis or any other cache mechanism. For asynchronous caching the Resque or Sidekiq adapters can be used, for synchronous - inline.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'redisize'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install redisize
## Usage
### Initialization
Usually adapter can'be defined automatically of presently installed gems. Curretly are supported sidekiq and resque gems to ansyncronous caching (redisizing). If no such gems are installed, the synchronous **inline** adapter is used. You can redefine manually an adapter as follows:```ruby
Redisize.adapter_kind = :inline
```Other values are ```:resque```, and ```:sidekiq```.
And then to use the gem just define in the target object:```ruby
include(Redisize)
```### In Rails
To use the cache feature with Rails (and ActiveRecord) you have just to wrap a method accessing DB either a record or a relation to a block like this. So to redisize a record value as a json use the follwing:
```ruby
redisize_json(attrs) do
#
# generate_json(attrs, options)
end
```to drop a JSON value use:
```ruby
deredisize_json(attrs)
```to redisize an SQL:
```ruby
redisize_sql do
relation.as_json(context)
end
```to redisize an record instance use:
```ruby
redisize_model(slug, by_key: :slug) do
self.joins(:slug).where(slugs: {text: slug}).first
end
```Next calls to the block will return a cached value. Updating the record will drop cache for sql or record itself.
## Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/majioa/redisize. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/majioa/redisize/blob/master/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Redisize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/majioa/redisize/blob/master/CODE_OF_CONDUCT.md).