Skip to content

Commit

Permalink
[mem-cache-store] Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
0exp committed Sep 1, 2018
1 parent 2152d23 commit 9af329f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
55 changes: 37 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Supported clients:
- `Redis` ([gem redis](https://github.com/redis/redis-rb)) ([redis storage](https://redis.io/))
- `Redis::Store` ([gem redis-store](https://github.com/redis-store/redis-store)) ([redis storage](https://redis.io/))
- `Dalli::Client` ([gem dalli](https://github.com/petergoldstein/dalli)) ([memcached storage](https://memcached.org/))
- `ActiveSupport::Cache::RedisCacheStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb)) ([redis cache storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html))
- `ActiveSupport::Cache::MemCacheStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/mem_cache_store.rb)) ([memcache storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/MemCacheStore.html))
- `ActiveSupport::Cache::FileStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/file_store.rb)) ([file storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/FileStore.html))
- `ActiveSupport::Cache::MemoryStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/memory_store.rb)) ([in memory storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html))
- `ActiveSupport::Cache::RedisCacheStore` ([gem activesupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb)) ([redis cache storage](https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html))

---

Expand Down Expand Up @@ -40,9 +41,10 @@ require 'any_cache'
- [AnyCache with Redis](#anycache-with-redis)
- [AnyCache with Redis::Store](#anycache-with-redisstore)
- [AnyCache with Dalli::Client](#anycache-with-dalliclient)
- [AnyCache with ActiveSupport::Cache::RedisCacheStore](#anycache-with-activesupportcacherediscachestore)
- [AnyCache with ActiveSupport::Cache::MemCacheStore](#anycache-with-activesupportmemcachestore)
- [AnyCache with ActiveSupport::Cache::FileStore](#anycache-with-activesupportcachefilestore)
- [AnyCache with ActiveSupport::Cache::MemoryStore](#anycache-with-activesupportcachememorystore)
- [AnyCache with ActiveSupport::Cache::RedisCacheStore](#anycache-with-activesupportcacherediscachestore)
- [Many cache storages](#many-cache-storages)
- [Custom cache clients](#custom-cache-clients)
- [Operations](#operations)
Expand All @@ -67,6 +69,7 @@ Supported clients:
- `Redis`
- `Redis::Store`
- `Dalli::Client`
- `ActiveSupport::Cache::MemCacheStore`
- `ActiveSupport::Cache::RedisCacheStore`
- `ActiveSupport::Cache::FileStore`
- `ActiveSupport::Cache::MemoryStore`
Expand All @@ -89,6 +92,8 @@ client = Redis::Store.new(...)
client = Dalli::Client.new(...)
# -- or --
client = ActiveSupport::Cache::RedisCacheStore.new(...)
# --- or ---
client = ActiveSupport::Cache::MemCacheStore.new(...)
# -- or --
client = ActiveSupport::Cache::FileStore.new(...)
# -- or --
Expand All @@ -109,12 +114,13 @@ storage instantiation works via `.build` method without explicit attributes.

Supported drivers:

- `:redis` - Redis;
- `:redis_tore` - Redis::Client;
- `:dalli` - Dalli::Client
- `:as_redis_cache_store` - ActiveSupport::Cache::RedisCacheStore;
- `:as_file_store` - ActiveSupport::Cache::FileStore;
- `:as_memory_store` - ActiveSupport::Cache::MemoryStore;
- `:redis` - [Redis](#anycache-with-redis);
- `:redis_tore` - [Redis::Client](#anycache-with-redisstore);
- `:dalli` - [Dalli::Clien](#anycache-with-dalliclient);
- `:as_redis_cache_store` - [ActiveSupport::Cache::RedisCacheStore](#anycache-with-activesupportcacherediscachestore);
- `:as_mem_cache_store` - [ActiveSupport::Cache::MemCacheStore](#anycache-with-activesupportcachememcachestore);
- `:as_file_store` - [ActiveSupport::Cache::FileStore](#anycache-with-activesupportcachefilestore);
- `:as_memory_store` - [ActiveSupport::Cache::MemoryStore](#anycache-with-activesupportcachememorystore);

##### `AnyCache` with `Redis`:

Expand Down Expand Up @@ -143,41 +149,54 @@ AnyCache.build
```ruby
AnyCache.configure do |conf|
conf.driver = :dalli
conf.dalli.servers = ... # string or array of strings
conf.dalli.options = { ... } # Dalli::Client-related options
end

AnyCache.build
```

##### `AnyCache` with `ActiveSupport::Cache::FileStore`:
##### `AnyCache` with `ActiveSupport::Cache::RedisCacheStore`:

```ruby
AnyCache.configure do |conf|
conf.driver = :as_file_store
conf.as_file_store.cache_path = '/path/to/cache'
conf.as_file_store.options = { ... } # ActiveSupport::Cache::FileStore-related options
conf.driver = :as_redis_cache_store
conf.as_redis_cache_store.options = { ... } # ActiveSupport::Cache::RedisCacheStore-related options
end

AnyCache.build
```

##### `AnyCache` with `ActiveSupport::Cache::MemoryStore`:
##### `AnyCache` with `ActiveSupport::Cache::MemCacheStore`:

```ruby
AnyCache.configure do |conf|
conf.driver = :as_memory_store
conf.as_memory_store.options = { ... } # ActiveSupport::Cache::MemoryStore-related options
conf.driver = :as_mem_cache_store
conf.as_memory_store.servers = ... # string or array of strings
conf.as_memory_store.options = { ... } # ActiveSupport::Cache::MemCacheStore-related options
end

AnyCache.build
```

##### `AnyCache` with `ActiveSupport::Cache::RedisCacheStore`:
##### `AnyCache` with `ActiveSupport::Cache::FileStore`:

```ruby
AnyCache.configure do |conf|
conf.driver = :as_redis_cache_store
conf.as_redis_cache_store.options = { ... } # ActiveSupport::Cache::RedisCacheStore-related options
conf.driver = :as_file_store
conf.as_file_store.cache_path = '/path/to/cache'
conf.as_file_store.options = { ... } # ActiveSupport::Cache::FileStore-related options
end

AnyCache.build
```

##### `AnyCache` with `ActiveSupport::Cache::MemoryStore`:

```ruby
AnyCache.configure do |conf|
conf.driver = :as_memory_store
conf.as_memory_store.options = { ... } # ActiveSupport::Cache::MemoryStore-related options
end

AnyCache.build
Expand Down
2 changes: 1 addition & 1 deletion lib/any_cache/adapters/active_support_mem_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
if is_initial
# NOTE: Dalli::Client can't decrement:
# - non-raw values;
# - values lower lower than zero
# - values lower lower than zero;
# - empty entries;
write(key, INITIAL_DECREMNETED_VALUE, expires_in: expires_in) && INITIAL_DECREMNETED_VALUE
else
Expand Down

0 comments on commit 9af329f

Please sign in to comment.