-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FCXPINFRA-76] Added cache for token
- Loading branch information
Showing
10 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'moneta' | ||
|
||
module LittleMonster | ||
module Tiger | ||
class Cache | ||
include Singleton | ||
|
||
attr_reader :cache | ||
|
||
def initialize | ||
@cache = Moneta.new(:Memory, expires: true) | ||
end | ||
|
||
def set(key, value, expires = 0) | ||
@cache.store(key, value, expires: expires) | ||
end | ||
|
||
def get(key) | ||
@cache[key] | ||
end | ||
|
||
def clear | ||
@cache.clear | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe LittleMonster::Tiger::Cache do | ||
subject(:cache) { described_class } | ||
|
||
let(:key) { SecureRandom.uuid } | ||
|
||
before do | ||
LittleMonster::Tiger::Cache.instance.cache.clear | ||
cache.instance.set(:key, key) | ||
end | ||
|
||
describe '.set' do | ||
context 'when set a key and value' do | ||
before do | ||
cache.instance.set(:key, key) | ||
end | ||
|
||
it 'store that value for that key' do | ||
expect(cache.instance.get(:key)).to eq(key) | ||
end | ||
end | ||
|
||
context 'when set a key, value and expires' do | ||
let(:expires) { 1 } | ||
|
||
before do | ||
cache.instance.set(:key, key, expires) | ||
end | ||
|
||
it 'store that value for that key for `expires` seconds' do | ||
expect(cache.instance.get(:key)).to eq(key) | ||
Kernel.sleep(expires + 1) | ||
expect(cache.instance.get(:key)).to be_nil | ||
end | ||
end | ||
end | ||
|
||
describe '.get' do | ||
context 'when get from a not exist key' do | ||
it 'return nil' do | ||
expect(cache.instance.get(:foo)).to be_nil | ||
end | ||
end | ||
end | ||
|
||
describe '.clear' do | ||
context 'when get a exist key after clear cache' do | ||
|
||
before do | ||
LittleMonster::Tiger::Cache.instance.cache.clear | ||
end | ||
|
||
it 'return nil' do | ||
expect(cache.instance.get(:key)).to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImFkNGYyMWRkLTgwZTItNGY2ZC1iOGY0LWE4OTE2ZDY0YTFhZiIsInR5cCI6IkpXVCJ9.eyJhZGRpdGlvbmFsX2luZm8iOnsiZW1haWwiOiJleGFtcGxlIiwiZnVsbF9uYW1lIjoiZXhhbXBsZSIsInVzZXJuYW1lIjoiZXhhbXBsZSJ9LCJleHAiOjQ3OTM4NzEyNzUsImlhdCI6MTY0MDI3MTI3NSwiaWRlbnRpdHkiOiJtcm46c2VnaW5mOmFkOnVzZXIvZXhhbXBsZSIsImlzcyI6ImZ1cnlfdGlnZXIiLCJzdWIiOiJleGFtcGxlIn0.OsfqgNjn52j_xxMRKNssDJQIgdVU4yVWVDnisI6yRGDyYw-hQ2-WnaHN9e5Obwpy6E0WDtdnt4Hk8nzk4QvMSQ" | ||
"token": "foo" | ||
} |