Skip to content

Commit

Permalink
rename to mem_cache_store
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Jan 11, 2021
1 parent ad6caaa commit 750ff10
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Cache::MemcachedStore
# Cache::MemCacheStore

[![Build Status](https://travis-ci.org/crystal-cache/memcached_cache.svg?branch=main)](https://travis-ci.org/crystal-cache/memcached_cache)
[![GitHub release](https://img.shields.io/github/release/crystal-cache/memcached_cache.svg)](https://github.com/crystal-cache/memcached_cache/releases)
[![Build Status](https://travis-ci.org/crystal-cache/mem_cache_store.svg?branch=main)](https://travis-ci.org/crystal-cache/mem_cache_store)
[![GitHub release](https://img.shields.io/github/release/crystal-cache/mem_cache_store.svg)](https://github.com/crystal-cache/mem_cache_store/releases)

A [cache](https://github.com/crystal-cache/cache) store implementation that stores data in Memcached.

Expand All @@ -11,20 +11,20 @@ A [cache](https://github.com/crystal-cache/cache) store implementation that stor

```yaml
dependencies:
memcached_cache:
github: crystal-cache/memcached_cache
mem_cache_store:
github: crystal-cache/mem_cache_store
```
2. Run `shards install`

## Usage

```crystal
require "memcached_cache"
require "mem_cache_store"
```

```crystal
cache = Cache::MemcachedStore(String, String).new(expires_in: 1.minute)
cache = Cache::MemCacheStore(String, String).new(expires_in: 1.minute)
cache.fetch("today") do
Time.utc.day_of_week
end
Expand All @@ -38,12 +38,12 @@ If you need to connect to a remote server or a different port, try:

```crystal
memcached = Memcached::Client.new(host: "10.0.1.1", port: 11211)
cache = Cache::MemcachedStore(String, String).new(expires_in: 1.minute, cache: memcached)
cache = Cache::MemCacheStore(String, String).new(expires_in: 1.minute, cache: memcached)
```

## Contributing

1. Fork it (<https://github.com/crystal-cache/memcached_cache/fork>)
1. Fork it (<https://github.com/crystal-cache/mem_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`)
Expand Down
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: memcached_cache
version: 0.1.1
name: mem_cache_store
version: 0.2.0

authors:
- Anton Maminov <[email protected]>
Expand Down
36 changes: 18 additions & 18 deletions spec/memcached_cache_spec.cr → spec/mem_cache_store_spec.cr
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
require "./spec_helper"

describe Cache do
context Cache::MemcachedStore do
context Cache::MemCacheStore do
Spec.before_each do
memcached = Memcached::Client.new
memcached.flush
end

it "initialize" do
store = Cache::MemcachedStore(String, String).new(expires_in: 12.hours)
store = Cache::MemCacheStore(String, String).new(expires_in: 12.hours)

store.should be_a(Cache::Store(String, String))
end

it "initialize with memcached" do
memcached = Memcached::Client.new(host: "localhost", port: 11211)
store = Cache::MemcachedStore(String, String).new(expires_in: 12.hours, cache: memcached)
store = Cache::MemCacheStore(String, String).new(expires_in: 12.hours, cache: memcached)

store.should be_a(Cache::Store(String, String))
end

it "write to cache first time" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
end

it "fetch from cache" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
Expand All @@ -39,7 +39,7 @@ describe Cache do

it "fetch from cache with custom Memcached" do
memcached = Memcached::Client.new(host: "localhost", port: 11211)
store = Cache::MemcachedStore(String, String).new(expires_in: 12.hours, cache: memcached)
store = Cache::MemCacheStore(String, String).new(expires_in: 12.hours, cache: memcached)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
Expand All @@ -49,7 +49,7 @@ describe Cache do
end

it "don't fetch from cache if expired" do
store = Cache::MemcachedStore(String, String).new(1.seconds)
store = Cache::MemCacheStore(String, String).new(1.seconds)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
Expand All @@ -61,7 +61,7 @@ describe Cache do
end

it "fetch with expires_in from cache" do
store = Cache::MemcachedStore(String, String).new(1.seconds)
store = Cache::MemCacheStore(String, String).new(1.seconds)

value = store.fetch("foo", expires_in: 1.hours) { "bar" }
value.should eq("bar")
Expand All @@ -73,7 +73,7 @@ describe Cache do
end

it "don't fetch with expires_in from cache if expires" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)

value = store.fetch("foo", expires_in: 1.seconds) { "bar" }
value.should eq("bar")
Expand All @@ -85,23 +85,23 @@ describe Cache do
end

it "write" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)
store.write("foo", "bar", expires_in: 1.minute)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
end

it "read" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)
store.write("foo", "bar")

value = store.read("foo")
value.should eq("bar")
end

it "set a custom expires_in value for entry on write" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)
store.write("foo", "bar", expires_in: 1.second)

sleep 2
Expand All @@ -111,7 +111,7 @@ describe Cache do
end

it "delete from cache" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
Expand All @@ -125,7 +125,7 @@ describe Cache do
end

it "deletes all items from the cache" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)

value = store.fetch("foo") { "bar" }
value.should eq("bar")
Expand All @@ -138,7 +138,7 @@ describe Cache do
end

it "#exists?" do
store = Cache::MemcachedStore(String, String).new(12.hours)
store = Cache::MemCacheStore(String, String).new(12.hours)

store.write("foo", "bar")

Expand All @@ -147,7 +147,7 @@ describe Cache do
end

it "#exists? expires" do
store = Cache::MemcachedStore(String, String).new(1.second)
store = Cache::MemCacheStore(String, String).new(1.second)

store.write("foo", "bar")

Expand All @@ -157,7 +157,7 @@ describe Cache do
end

it "#increment" do
store = Cache::MemcachedStore(String, Int32).new(12.hours)
store = Cache::MemCacheStore(String, Int32).new(12.hours)

store.write("num", 1)
store.increment("num", 1)
Expand All @@ -168,7 +168,7 @@ describe Cache do
end

it "#decrement" do
store = Cache::MemcachedStore(String, Int32).new(12.hours)
store = Cache::MemCacheStore(String, Int32).new(12.hours)

store.write("num", 2)
store.decrement("num", 1)
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require "spec"
require "../src/memcached_cache"
require "../src/mem_cache_store"
4 changes: 2 additions & 2 deletions src/memcached_cache.cr → src/mem_cache_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ module Cache
# A cache store implementation which stores data in Memcached.
#
# ```crystal
# cache = Cache::MemcachedStore(String, String).new(expires_in: 1.minute)
# cache = Cache::MemCacheStore(String, String).new(expires_in: 1.minute)
# cache.fetch("today") do
# Time.utc.day_of_week
# end
# ```
#
# This assumes Memcached was started with a default configuration, and is listening on `localhost:11211`.
struct MemcachedStore(K, V) < Store(K, V)
struct MemCacheStore(K, V) < Store(K, V)
@cache : Memcached::Client

def initialize(@expires_in : Time::Span, @cache = Memcached::Client.new)
Expand Down

0 comments on commit 750ff10

Please sign in to comment.