Created
December 3, 2008 11:40
-
-
Save zmalltalker/31506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Hitting Memcached while running tests is a _really_ bad idea. This class is basically a glorified hash, keeping track of what's given to it, | |
# seems to work acceptably in test env. | |
# The way the Cache module works, it assumes a constant named CACHE to keep the actual holder for cached data - this class provides what seems to be needed for the | |
# engine not to complain | |
class MockCached | |
class Value | |
attr_reader :value | |
def initialize(value, expiry=nil) | |
@value = value | |
@expiry = expiry | |
end | |
end | |
def initialize(cluster, namespace) | |
@contents = {} | |
end | |
def set(key, value, expiry) | |
@contents[key] = Value.new(value, expiry) | |
end | |
def add(key, value, expiry) | |
@contents[key] = Value.new(value, expiry) | |
end | |
def delete(key, delay) | |
@contents.delete(key) | |
end | |
def get(key) | |
@contents[key].value rescue nil | |
end | |
def reset | |
@contents.clear | |
end | |
end | |
# Here is where we assign the constant | |
CACHE = MockCached.new(nil, nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment