Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zarqman/smart_cache_store
Production-ready enhancements for mem_cache_store and redis_cache_store. For Rails or ActiveSupport.
https://github.com/zarqman/smart_cache_store
memcache rails redis
Last synced: 2 days ago
JSON representation
Production-ready enhancements for mem_cache_store and redis_cache_store. For Rails or ActiveSupport.
- Host: GitHub
- URL: https://github.com/zarqman/smart_cache_store
- Owner: zarqman
- License: mit
- Created: 2021-11-18T17:00:07.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-05T22:03:48.000Z (about 1 year ago)
- Last Synced: 2024-10-13T16:51:41.550Z (about 1 month ago)
- Topics: memcache, rails, redis
- Language: Ruby
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SmartCacheStore
SmartCacheStore provides variations on ActiveSupport's MemCacheStore and RedisCacheStore to make the default configurations more production ready. It does this by setting better defaults and using a few more ENVs.
##### Redis -- SmartRedisCache
Set by default:
url: ENV['REDIS_URL']
namespace: ENV['REDIS_NAMESPACE']
expires_in: 1.day
race_condition_ttl: 5.seconds
pool: ENV['RAILS_MAX_THREADS'] || 5
connect_timeout: 2
read_timeout: 1
write_timeout: 1
reconnect_attempts: [0.2]`:url` should be a uri, like: `redis://localhost:6379/0`. For two or more uris, combine with a comma: `redis://host-a,redis://host-b`.
Any of these may still be specified directly, as well as all other support parameters for RedisCacheStore or the Redis gem.
##### Memcache -- SmartMemCache
Set by default:
url: ENV['MEMCACHE_SERVERS']
namespace: ENV['MEMCACHE_NAMESPACE']
expires_in: 1.day
race_condition_ttl: 5.seconds
failover: true
pool: ENV['RAILS_MAX_THREADS'] || 5MemCacheStore's legacy initializer with `*addresses` as the first parameter, and the RedisCacheStore compatible `:url` are supported.
`:url` or *addresses should be a uri, like: `memcached://localhost:11211`. For two or more uris, combine with a comma: `memcached://host-a,memcached://host-b`.
### Other features
SmartMemCache's increment() and decrement() are also enhanced to be able to act on previously unset keys.
## Usage
In `environment/[env].rb`:
#### Redis
# basic:
config.cache_store = :smart_redis_cache
# with parameters:
config.cache_store = :smart_redis_cache, {url: 'redis://localhost:1234/9'}#### Memcache
# basic:
config.cache_store = :smart_mem_cache
# with parameters:
config.cache_store = :smart_mem_cache, 'memcached://localhost:1234'
config.cache_store = :smart_mem_cache, 'memcached://localhost:1234', {expires_in: 1.hour}
config.cache_store = :smart_mem_cache, {url: 'memcached://localhost:1234', expires_in: 1.hour}## Installation
Add `smart_cache_store` plus one driver to your application's Gemfile:```ruby
gem 'redis' # for redis; gem v4.x or 5.x
# OR
gem 'dalli' # for memcachegem "smart_cache_store"
```And then execute:
```bash
$ bundle
```## Contributing
1. Fork it ( https://github.com/zarqman/smart_cache_store/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).