Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanety/activerecord_translation_cache
https://github.com/kanety/activerecord_translation_cache
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kanety/activerecord_translation_cache
- Owner: kanety
- License: mit
- Created: 2021-07-10T08:31:46.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-02T03:35:22.000Z (about 2 years ago)
- Last Synced: 2024-12-25T04:04:42.314Z (23 days ago)
- Language: Ruby
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ActiverecordTranslationCache
A memoized cache for ActiveRecord translations.
## Dependencies
* ruby 2.5+
* activerecord 6.0+
* activesupport 6.0+## Installation
Add this line to your application's Gemfile:
```ruby
gem 'activerecord_translation_cache'
```Then execute:
$ bundle
## Usage
Enable cache as follows:
```ruby
ActiverecordTranslationCache.enable do
puts ItemModel.human_attribute_name(:column) # cached
puts ItemModel.human_attribute_name(:column) # cache hit
puts ItemModel.model_name.human # cached
puts ItemModel.model_name.human # cache hit
end
```In the `enable` block, return values of `human_attribute_name` and `human` are cached for each model,
and cache is used at next call.
Note that cache is cleared when block is end.### Rack middleware
Rack middleware is available when you want to enable cache globally:
```ruby
Rails.application.config.middleware.use ActiverecordTranslationCache::Middleware
```## Contributing
Bug reports and pull requests are welcome at https://github.com/kanety/activerecord_translation_cache.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).