2009-07-01 19:56:43 -04:00
|
|
|
require 'logger'
|
2008-01-05 08:31:04 -05:00
|
|
|
require 'abstract_unit'
|
2009-03-29 02:56:14 -04:00
|
|
|
require 'active_support/cache'
|
2013-03-12 01:03:32 -04:00
|
|
|
require 'dependencies_test_helpers'
|
2008-01-03 16:05:12 -05:00
|
|
|
|
2014-01-08 18:48:19 -05:00
|
|
|
module ActiveSupport
|
|
|
|
module Cache
|
|
|
|
module Strategy
|
|
|
|
module LocalCache
|
|
|
|
class MiddlewareTest < ActiveSupport::TestCase
|
|
|
|
def test_local_cache_cleared_on_close
|
|
|
|
key = "super awesome key"
|
|
|
|
assert_nil LocalCacheRegistry.cache_for key
|
|
|
|
middleware = Middleware.new('<3', key).new(->(env) {
|
|
|
|
assert LocalCacheRegistry.cache_for(key), 'should have a cache'
|
|
|
|
[200, {}, []]
|
|
|
|
})
|
|
|
|
_, _, body = middleware.call({})
|
|
|
|
assert LocalCacheRegistry.cache_for(key), 'should still have a cache'
|
|
|
|
body.each { }
|
|
|
|
assert LocalCacheRegistry.cache_for(key), 'should still have a cache'
|
|
|
|
body.close
|
|
|
|
assert_nil LocalCacheRegistry.cache_for(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_local_cache_cleared_on_exception
|
|
|
|
key = "super awesome key"
|
|
|
|
assert_nil LocalCacheRegistry.cache_for key
|
|
|
|
middleware = Middleware.new('<3', key).new(->(env) {
|
|
|
|
assert LocalCacheRegistry.cache_for(key), 'should have a cache'
|
|
|
|
raise
|
|
|
|
})
|
|
|
|
assert_raises(RuntimeError) { middleware.call({}) }
|
|
|
|
assert_nil LocalCacheRegistry.cache_for(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-15 22:28:10 -05:00
|
|
|
class CacheKeyTest < ActiveSupport::TestCase
|
2012-10-11 21:26:41 -04:00
|
|
|
def test_entry_legacy_optional_ivars
|
|
|
|
legacy = Class.new(ActiveSupport::Cache::Entry) do
|
|
|
|
def initialize(value, options = {})
|
|
|
|
@value = value
|
|
|
|
@expires_in = nil
|
|
|
|
@created_at = nil
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
entry = legacy.new 'foo'
|
|
|
|
assert_equal 'foo', entry.value
|
|
|
|
end
|
|
|
|
|
2008-06-20 03:25:41 -04:00
|
|
|
def test_expand_cache_key
|
2012-01-27 14:41:37 -05:00
|
|
|
assert_equal '1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true])
|
|
|
|
assert_equal 'name/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name)
|
2008-06-20 03:25:41 -04:00
|
|
|
end
|
2010-07-27 09:41:11 -04:00
|
|
|
|
|
|
|
def test_expand_cache_key_with_rails_cache_id
|
2010-07-27 09:57:15 -04:00
|
|
|
begin
|
|
|
|
ENV['RAILS_CACHE_ID'] = 'c99'
|
|
|
|
assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo)
|
2012-01-27 14:41:37 -05:00
|
|
|
assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo])
|
|
|
|
assert_equal 'c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar])
|
2010-07-27 09:57:15 -04:00
|
|
|
assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm)
|
2012-01-27 14:41:37 -05:00
|
|
|
assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm)
|
|
|
|
assert_equal 'nm/c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm)
|
2010-07-27 09:57:15 -04:00
|
|
|
ensure
|
|
|
|
ENV['RAILS_CACHE_ID'] = nil
|
|
|
|
end
|
2010-07-27 09:41:11 -04:00
|
|
|
end
|
2010-07-27 09:47:59 -04:00
|
|
|
|
|
|
|
def test_expand_cache_key_with_rails_app_version
|
2010-07-27 09:57:15 -04:00
|
|
|
begin
|
|
|
|
ENV['RAILS_APP_VERSION'] = 'rails3'
|
|
|
|
assert_equal 'rails3/foo', ActiveSupport::Cache.expand_cache_key(:foo)
|
|
|
|
ensure
|
|
|
|
ENV['RAILS_APP_VERSION'] = nil
|
|
|
|
end
|
2010-07-27 09:47:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_expand_cache_key_rails_cache_id_should_win_over_rails_app_version
|
2010-07-27 09:57:15 -04:00
|
|
|
begin
|
|
|
|
ENV['RAILS_CACHE_ID'] = 'c99'
|
|
|
|
ENV['RAILS_APP_VERSION'] = 'rails3'
|
|
|
|
assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo)
|
|
|
|
ensure
|
|
|
|
ENV['RAILS_CACHE_ID'] = nil
|
|
|
|
ENV['RAILS_APP_VERSION'] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-23 12:11:36 -05:00
|
|
|
def test_expand_cache_key_respond_to_cache_key
|
2010-07-27 09:57:15 -04:00
|
|
|
key = 'foo'
|
|
|
|
def key.cache_key
|
|
|
|
:foo_key
|
|
|
|
end
|
|
|
|
assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key(key)
|
2010-07-27 09:47:59 -04:00
|
|
|
end
|
|
|
|
|
2011-11-23 12:11:36 -05:00
|
|
|
def test_expand_cache_key_array_with_something_that_responds_to_cache_key
|
2011-11-23 12:06:15 -05:00
|
|
|
key = 'foo'
|
|
|
|
def key.cache_key
|
|
|
|
:foo_key
|
|
|
|
end
|
2012-01-27 14:41:37 -05:00
|
|
|
assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key([key])
|
2011-11-23 12:06:15 -05:00
|
|
|
end
|
|
|
|
|
2011-11-23 12:11:36 -05:00
|
|
|
def test_expand_cache_key_of_nil
|
|
|
|
assert_equal '', ActiveSupport::Cache.expand_cache_key(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_expand_cache_key_of_false
|
|
|
|
assert_equal 'false', ActiveSupport::Cache.expand_cache_key(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_expand_cache_key_of_true
|
|
|
|
assert_equal 'true', ActiveSupport::Cache.expand_cache_key(true)
|
|
|
|
end
|
2012-10-23 03:04:42 -04:00
|
|
|
|
2012-03-12 00:21:37 -04:00
|
|
|
def test_expand_cache_key_of_array_like_object
|
|
|
|
assert_equal 'foo/bar/baz', ActiveSupport::Cache.expand_cache_key(%w{foo bar baz}.to_enum)
|
|
|
|
end
|
2008-06-20 03:25:41 -04:00
|
|
|
end
|
|
|
|
|
2009-01-15 22:28:10 -05:00
|
|
|
class CacheStoreSettingTest < ActiveSupport::TestCase
|
2008-01-03 16:05:12 -05:00
|
|
|
def test_file_fragment_cache_store
|
|
|
|
store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory"
|
|
|
|
assert_kind_of(ActiveSupport::Cache::FileStore, store)
|
|
|
|
assert_equal "/path/to/cache/directory", store.cache_path
|
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
2008-01-03 16:05:12 -05:00
|
|
|
def test_mem_cache_fragment_cache_store
|
2012-06-28 22:47:46 -04:00
|
|
|
Dalli::Client.expects(:new).with(%w[localhost], {})
|
2008-01-03 16:05:12 -05:00
|
|
|
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
|
|
|
|
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
2009-05-19 10:24:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mem_cache_fragment_cache_store_with_given_mem_cache
|
2012-06-28 22:47:46 -04:00
|
|
|
mem_cache = Dalli::Client.new
|
|
|
|
Dalli::Client.expects(:new).never
|
2009-05-19 10:24:26 -04:00
|
|
|
store = ActiveSupport::Cache.lookup_store :mem_cache_store, mem_cache
|
|
|
|
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
2008-01-03 16:05:12 -05:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
2014-01-03 16:39:50 -05:00
|
|
|
def test_mem_cache_fragment_cache_store_with_not_dalli_client
|
|
|
|
Dalli::Client.expects(:new).never
|
|
|
|
memcache = Object.new
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
ActiveSupport::Cache.lookup_store :mem_cache_store, memcache
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-04-17 13:58:31 -04:00
|
|
|
def test_mem_cache_fragment_cache_store_with_multiple_servers
|
2012-06-28 22:47:46 -04:00
|
|
|
Dalli::Client.expects(:new).with(%w[localhost 192.168.1.1], {})
|
2008-04-17 13:58:31 -04:00
|
|
|
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'
|
|
|
|
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
2008-04-17 13:58:31 -04:00
|
|
|
def test_mem_cache_fragment_cache_store_with_options
|
2012-06-28 22:47:46 -04:00
|
|
|
Dalli::Client.expects(:new).with(%w[localhost 192.168.1.1], { :timeout => 10 })
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1', :namespace => 'foo', :timeout => 10
|
2008-04-17 13:58:31 -04:00
|
|
|
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal 'foo', store.options[:namespace]
|
2008-04-17 13:58:31 -04:00
|
|
|
end
|
2008-01-03 16:05:12 -05:00
|
|
|
|
|
|
|
def test_object_assigned_fragment_cache_store
|
|
|
|
store = ActiveSupport::Cache.lookup_store ActiveSupport::Cache::FileStore.new("/path/to/cache/directory")
|
|
|
|
assert_kind_of(ActiveSupport::Cache::FileStore, store)
|
|
|
|
assert_equal "/path/to/cache/directory", store.cache_path
|
|
|
|
end
|
|
|
|
end
|
2008-01-31 20:43:47 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
class CacheStoreNamespaceTest < ActiveSupport::TestCase
|
|
|
|
def test_static_namespace
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "tester")
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
assert_equal "bar", cache.read("foo")
|
|
|
|
assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_proc_namespace
|
|
|
|
test_val = "tester"
|
|
|
|
proc = lambda{test_val}
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => proc)
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
assert_equal "bar", cache.read("foo")
|
|
|
|
assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_matched_key_start
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "tester")
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
cache.write("fu", "baz")
|
|
|
|
cache.delete_matched(/^fo/)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert !cache.exist?("foo")
|
|
|
|
assert cache.exist?("fu")
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_matched_key
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "foo")
|
|
|
|
cache.write("foo", "bar")
|
|
|
|
cache.write("fu", "baz")
|
|
|
|
cache.delete_matched(/OO/i)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert !cache.exist?("foo")
|
|
|
|
assert cache.exist?("fu")
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tests the base functionality that should be identical across all cache stores.
|
|
|
|
module CacheStoreBehavior
|
|
|
|
def test_should_read_and_write_strings
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write('foo', 'bar')
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal 'bar', @cache.read('foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_overwrite
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@cache.write('foo', 'baz')
|
|
|
|
assert_equal 'baz', @cache.read('foo')
|
2008-11-22 18:19:19 -05:00
|
|
|
end
|
2008-01-31 20:43:47 -05:00
|
|
|
|
2008-11-22 18:19:19 -05:00
|
|
|
def test_fetch_without_cache_miss
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.write('foo', 'bar')
|
2008-11-22 18:19:19 -05:00
|
|
|
@cache.expects(:write).never
|
|
|
|
assert_equal 'bar', @cache.fetch('foo') { 'baz' }
|
|
|
|
end
|
2008-01-31 20:43:47 -05:00
|
|
|
|
2008-11-22 18:19:19 -05:00
|
|
|
def test_fetch_with_cache_miss
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.expects(:write).with('foo', 'baz', @cache.options)
|
2008-11-22 18:19:19 -05:00
|
|
|
assert_equal 'baz', @cache.fetch('foo') { 'baz' }
|
|
|
|
end
|
2008-01-31 20:43:47 -05:00
|
|
|
|
2012-10-23 03:04:42 -04:00
|
|
|
def test_fetch_with_cache_miss_passes_key_to_block
|
2012-10-23 21:42:37 -04:00
|
|
|
cache_miss = false
|
|
|
|
assert_equal 3, @cache.fetch('foo') { |key| cache_miss = true; key.length }
|
|
|
|
assert cache_miss
|
|
|
|
|
|
|
|
cache_miss = false
|
|
|
|
assert_equal 3, @cache.fetch('foo') { |key| cache_miss = true; key.length }
|
|
|
|
assert !cache_miss
|
2012-10-23 03:04:42 -04:00
|
|
|
end
|
|
|
|
|
2008-11-22 18:19:19 -05:00
|
|
|
def test_fetch_with_forced_cache_miss
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.write('foo', 'bar')
|
2008-11-22 18:19:19 -05:00
|
|
|
@cache.expects(:read).never
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.expects(:write).with('foo', 'bar', @cache.options.merge(:force => true))
|
2008-11-22 18:19:19 -05:00
|
|
|
@cache.fetch('foo', :force => true) { 'bar' }
|
2008-01-31 20:43:47 -05:00
|
|
|
end
|
2008-08-13 21:57:26 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_fetch_with_cached_nil
|
|
|
|
@cache.write('foo', nil)
|
|
|
|
@cache.expects(:write).never
|
|
|
|
assert_nil @cache.fetch('foo') { 'baz' }
|
2008-08-13 21:57:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_read_and_write_hash
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write('foo', {:a => "b"})
|
2008-08-13 21:57:26 -04:00
|
|
|
assert_equal({:a => "b"}, @cache.read('foo'))
|
|
|
|
end
|
|
|
|
|
2009-01-28 22:20:46 -05:00
|
|
|
def test_should_read_and_write_integer
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write('foo', 1)
|
2009-01-28 22:20:46 -05:00
|
|
|
assert_equal 1, @cache.read('foo')
|
|
|
|
end
|
|
|
|
|
2008-08-13 21:57:26 -04:00
|
|
|
def test_should_read_and_write_nil
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write('foo', nil)
|
2008-08-13 21:57:26 -04:00
|
|
|
assert_equal nil, @cache.read('foo')
|
2008-08-18 21:14:56 -04:00
|
|
|
end
|
|
|
|
|
2011-07-08 07:08:37 -04:00
|
|
|
def test_should_read_and_write_false
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write('foo', false)
|
2011-11-21 17:14:11 -05:00
|
|
|
assert_equal false, @cache.read('foo')
|
2011-07-08 07:08:37 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_read_multi
|
2008-08-18 21:14:56 -04:00
|
|
|
@cache.write('foo', 'bar')
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.write('fu', 'baz')
|
|
|
|
@cache.write('fud', 'biz')
|
|
|
|
assert_equal({"foo" => "bar", "fu" => "baz"}, @cache.read_multi('foo', 'fu'))
|
2008-08-18 21:14:56 -04:00
|
|
|
end
|
2011-12-12 14:40:29 -05:00
|
|
|
|
2011-08-01 13:05:29 -04:00
|
|
|
def test_read_multi_with_expires
|
2012-09-30 12:26:04 -04:00
|
|
|
time = Time.now
|
|
|
|
@cache.write('foo', 'bar', :expires_in => 10)
|
2011-08-01 13:05:29 -04:00
|
|
|
@cache.write('fu', 'baz')
|
|
|
|
@cache.write('fud', 'biz')
|
2012-09-30 12:26:04 -04:00
|
|
|
Time.stubs(:now).returns(time + 11)
|
2011-08-01 13:05:29 -04:00
|
|
|
assert_equal({"fu" => "baz"}, @cache.read_multi('foo', 'fu'))
|
|
|
|
end
|
2008-08-18 21:14:56 -04:00
|
|
|
|
2013-04-15 10:41:27 -04:00
|
|
|
def test_fetch_multi
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@cache.write('fud', 'biz')
|
|
|
|
|
2013-07-17 14:59:15 -04:00
|
|
|
values = @cache.fetch_multi('foo', 'fu', 'fud') { |value| value * 2 }
|
2013-04-15 10:41:27 -04:00
|
|
|
|
2013-07-17 14:59:15 -04:00
|
|
|
assert_equal({ 'foo' => 'bar', 'fu' => 'fufu', 'fud' => 'biz' }, values)
|
|
|
|
assert_equal('fufu', @cache.read('fu'))
|
2013-04-15 10:41:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_multi_with_objects
|
2013-07-17 14:59:15 -04:00
|
|
|
foo = stub(:title => 'FOO!', :cache_key => 'foo')
|
|
|
|
bar = stub(:cache_key => 'bar')
|
2013-04-15 10:41:27 -04:00
|
|
|
|
2013-07-17 14:59:15 -04:00
|
|
|
@cache.write('bar', 'BAM!')
|
2013-04-15 10:41:27 -04:00
|
|
|
|
2013-07-17 14:59:15 -04:00
|
|
|
values = @cache.fetch_multi(foo, bar) { |object| object.title }
|
|
|
|
|
|
|
|
assert_equal({ foo => 'FOO!', bar => 'BAM!' }, values)
|
2013-04-15 10:41:27 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_read_and_write_compressed_small_data
|
|
|
|
@cache.write('foo', 'bar', :compress => true)
|
|
|
|
assert_equal 'bar', @cache.read('foo')
|
2008-08-18 21:14:56 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_read_and_write_compressed_large_data
|
|
|
|
@cache.write('foo', 'bar', :compress => true, :compress_threshold => 2)
|
|
|
|
assert_equal 'bar', @cache.read('foo')
|
2008-08-18 21:14:56 -04:00
|
|
|
end
|
2008-08-19 20:20:10 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_read_and_write_compressed_nil
|
|
|
|
@cache.write('foo', nil, :compress => true)
|
|
|
|
assert_nil @cache.read('foo')
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_cache_key
|
|
|
|
obj = Object.new
|
|
|
|
def obj.cache_key
|
|
|
|
:foo
|
|
|
|
end
|
|
|
|
@cache.write(obj, "bar")
|
|
|
|
assert_equal "bar", @cache.read("foo")
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_param_as_cache_key
|
|
|
|
obj = Object.new
|
|
|
|
def obj.to_param
|
|
|
|
"foo"
|
|
|
|
end
|
|
|
|
@cache.write(obj, "bar")
|
|
|
|
assert_equal "bar", @cache.read("foo")
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_array_as_cache_key
|
|
|
|
@cache.write([:fu, "foo"], "bar")
|
|
|
|
assert_equal "bar", @cache.read("fu/foo")
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_hash_as_cache_key
|
|
|
|
@cache.write({:foo => 1, :fu => 2}, "bar")
|
|
|
|
assert_equal "bar", @cache.read("foo=1/fu=2")
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_keys_are_case_sensitive
|
|
|
|
@cache.write("foo", "bar")
|
|
|
|
assert_nil @cache.read("FOO")
|
|
|
|
end
|
2009-06-21 09:51:43 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_exist
|
2009-06-21 09:35:14 -04:00
|
|
|
@cache.write('foo', 'bar')
|
2013-07-07 21:59:32 -04:00
|
|
|
assert_equal true, @cache.exist?('foo')
|
|
|
|
assert_equal false, @cache.exist?('bar')
|
2009-06-21 09:35:14 -04:00
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_nil_exist
|
|
|
|
@cache.write('foo', nil)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?('foo')
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_delete
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
assert @cache.exist?('foo')
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.delete('foo')
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert !@cache.exist?('foo')
|
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
|
2009-07-01 15:16:55 -04:00
|
|
|
def test_original_store_objects_should_not_be_immutable
|
|
|
|
bar = 'bar'
|
|
|
|
@cache.write('foo', bar)
|
|
|
|
assert_nothing_raised { bar.gsub!(/.*/, 'baz') }
|
|
|
|
end
|
2010-04-19 02:01:44 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_expires_in
|
|
|
|
time = Time.local(2008, 4, 24)
|
|
|
|
Time.stubs(:now).returns(time)
|
|
|
|
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
assert_equal 'bar', @cache.read('foo')
|
|
|
|
|
|
|
|
Time.stubs(:now).returns(time + 30)
|
|
|
|
assert_equal 'bar', @cache.read('foo')
|
|
|
|
|
|
|
|
Time.stubs(:now).returns(time + 61)
|
|
|
|
assert_nil @cache.read('foo')
|
2010-04-19 02:01:44 -04:00
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_race_condition_protection
|
|
|
|
time = Time.now
|
|
|
|
@cache.write('foo', 'bar', :expires_in => 60)
|
|
|
|
Time.stubs(:now).returns(time + 61)
|
|
|
|
result = @cache.fetch('foo', :race_condition_ttl => 10) do
|
|
|
|
assert_equal 'bar', @cache.read('foo')
|
|
|
|
"baz"
|
2008-10-14 16:30:46 -04:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal "baz", result
|
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_race_condition_protection_is_limited
|
|
|
|
time = Time.now
|
|
|
|
@cache.write('foo', 'bar', :expires_in => 60)
|
|
|
|
Time.stubs(:now).returns(time + 71)
|
|
|
|
result = @cache.fetch('foo', :race_condition_ttl => 10) do
|
|
|
|
assert_equal nil, @cache.read('foo')
|
|
|
|
"baz"
|
|
|
|
end
|
|
|
|
assert_equal "baz", result
|
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_race_condition_protection_is_safe
|
|
|
|
time = Time.now
|
|
|
|
@cache.write('foo', 'bar', :expires_in => 60)
|
|
|
|
Time.stubs(:now).returns(time + 61)
|
|
|
|
begin
|
|
|
|
@cache.fetch('foo', :race_condition_ttl => 10) do
|
2009-01-15 22:28:10 -05:00
|
|
|
assert_equal 'bar', @cache.read('foo')
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
raise ArgumentError.new
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
2010-07-22 23:36:34 -04:00
|
|
|
rescue ArgumentError
|
2008-10-14 16:30:46 -04:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal "bar", @cache.read('foo')
|
2012-09-30 12:26:04 -04:00
|
|
|
Time.stubs(:now).returns(time + 91)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_nil @cache.read('foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_crazy_key_characters
|
|
|
|
crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-"
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write(crazy_key, "1", :raw => true)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal "1", @cache.read(crazy_key)
|
|
|
|
assert_equal "1", @cache.fetch(crazy_key)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.delete(crazy_key)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal "2", @cache.fetch(crazy_key, :raw => true) { "2" }
|
|
|
|
assert_equal 3, @cache.increment(crazy_key)
|
|
|
|
assert_equal 2, @cache.decrement(crazy_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_really_long_keys
|
|
|
|
key = ""
|
2011-09-22 00:03:59 -04:00
|
|
|
900.times{key << "x"}
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write(key, "bar")
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal "bar", @cache.read(key)
|
|
|
|
assert_equal "bar", @cache.fetch(key)
|
|
|
|
assert_nil @cache.read("#{key}x")
|
|
|
|
assert_equal({key => "bar"}, @cache.read_multi(key))
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.delete(key)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
end
|
2008-11-03 04:07:05 -05:00
|
|
|
|
2011-03-11 20:57:28 -05:00
|
|
|
# https://rails.lighthouseapp.com/projects/8994/tickets/6225-memcachestore-cant-deal-with-umlauts-and-special-characters
|
2013-04-10 05:20:29 -04:00
|
|
|
# The error is caused by character encodings that can't be compared with ASCII-8BIT regular expressions and by special
|
2011-03-11 20:57:28 -05:00
|
|
|
# characters like the umlaut in UTF-8.
|
|
|
|
module EncodedKeyCacheBehavior
|
2011-12-25 06:34:58 -05:00
|
|
|
Encoding.list.each do |encoding|
|
|
|
|
define_method "test_#{encoding.name.underscore}_encoded_values" do
|
|
|
|
key = "foo".force_encoding(encoding)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.write(key, "1", :raw => true)
|
2011-03-11 20:57:28 -05:00
|
|
|
assert_equal "1", @cache.read(key)
|
|
|
|
assert_equal "1", @cache.fetch(key)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.delete(key)
|
2011-03-11 20:57:28 -05:00
|
|
|
assert_equal "2", @cache.fetch(key, :raw => true) { "2" }
|
|
|
|
assert_equal 3, @cache.increment(key)
|
|
|
|
assert_equal 2, @cache.decrement(key)
|
|
|
|
end
|
2011-12-25 06:34:58 -05:00
|
|
|
end
|
2011-03-11 20:57:28 -05:00
|
|
|
|
2011-12-25 06:34:58 -05:00
|
|
|
def test_common_utf8_values
|
|
|
|
key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8)
|
|
|
|
assert @cache.write(key, "1", :raw => true)
|
|
|
|
assert_equal "1", @cache.read(key)
|
|
|
|
assert_equal "1", @cache.fetch(key)
|
|
|
|
assert @cache.delete(key)
|
|
|
|
assert_equal "2", @cache.fetch(key, :raw => true) { "2" }
|
|
|
|
assert_equal 3, @cache.increment(key)
|
|
|
|
assert_equal 2, @cache.decrement(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_retains_encoding
|
|
|
|
key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8)
|
|
|
|
assert @cache.write(key, "1", :raw => true)
|
|
|
|
assert_equal Encoding::UTF_8, key.encoding
|
2011-03-11 20:57:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
module CacheDeleteMatchedBehavior
|
|
|
|
def test_delete_matched
|
|
|
|
@cache.write("foo", "bar")
|
|
|
|
@cache.write("fu", "baz")
|
2010-10-23 00:55:17 -04:00
|
|
|
@cache.write("foo/bar", "baz")
|
|
|
|
@cache.write("fu/baz", "bar")
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.delete_matched(/oo/)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert !@cache.exist?("foo")
|
|
|
|
assert @cache.exist?("fu")
|
|
|
|
assert !@cache.exist?("foo/bar")
|
|
|
|
assert @cache.exist?("fu/baz")
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module CacheIncrementDecrementBehavior
|
|
|
|
def test_increment
|
|
|
|
@cache.write('foo', 1, :raw => true)
|
|
|
|
assert_equal 1, @cache.read('foo').to_i
|
|
|
|
assert_equal 2, @cache.increment('foo')
|
|
|
|
assert_equal 2, @cache.read('foo').to_i
|
|
|
|
assert_equal 3, @cache.increment('foo')
|
|
|
|
assert_equal 3, @cache.read('foo').to_i
|
2012-06-28 22:55:28 -04:00
|
|
|
assert_nil @cache.increment('bar')
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_decrement
|
|
|
|
@cache.write('foo', 3, :raw => true)
|
|
|
|
assert_equal 3, @cache.read('foo').to_i
|
|
|
|
assert_equal 2, @cache.decrement('foo')
|
|
|
|
assert_equal 2, @cache.read('foo').to_i
|
|
|
|
assert_equal 1, @cache.decrement('foo')
|
|
|
|
assert_equal 1, @cache.read('foo').to_i
|
2012-06-28 22:55:28 -04:00
|
|
|
assert_nil @cache.decrement('bar')
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module LocalCacheBehavior
|
|
|
|
def test_local_writes_are_persistent_on_the_remote_cache
|
|
|
|
retval = @cache.with_local_cache do
|
|
|
|
@cache.write('foo', 'bar')
|
2009-05-27 15:54:58 -04:00
|
|
|
end
|
2011-11-21 17:22:02 -05:00
|
|
|
assert retval
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_equal 'bar', @cache.read('foo')
|
|
|
|
end
|
2009-05-27 15:54:58 -04:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_clear_also_clears_local_cache
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@cache.clear
|
|
|
|
assert_nil @cache.read('foo')
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_nil @cache.read('foo')
|
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_write
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@peek.delete('foo')
|
2009-01-15 22:28:10 -05:00
|
|
|
assert_equal 'bar', @cache.read('foo')
|
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_read
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@cache.with_local_cache do
|
|
|
|
assert_equal 'bar', @cache.read('foo')
|
2008-11-03 04:07:05 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_write_nil
|
|
|
|
@cache.with_local_cache do
|
2010-05-16 09:37:57 -04:00
|
|
|
assert @cache.write('foo', nil)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
assert_nil @cache.read('foo')
|
|
|
|
@peek.write('foo', 'bar')
|
|
|
|
assert_nil @cache.read('foo')
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_delete
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@cache.delete('foo')
|
|
|
|
assert_nil @cache.read('foo')
|
2009-01-28 22:20:46 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-28 22:20:46 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_exist
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
@peek.delete('foo')
|
2010-05-16 09:37:57 -04:00
|
|
|
assert @cache.exist?('foo')
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_increment
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write('foo', 1, :raw => true)
|
|
|
|
@peek.write('foo', 2, :raw => true)
|
|
|
|
@cache.increment('foo')
|
|
|
|
assert_equal 3, @cache.read('foo')
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_local_cache_of_decrement
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write('foo', 1, :raw => true)
|
|
|
|
@peek.write('foo', 3, :raw => true)
|
|
|
|
@cache.decrement('foo')
|
|
|
|
assert_equal 2, @cache.read('foo')
|
2009-01-15 22:28:10 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_middleware
|
|
|
|
app = lambda { |env|
|
|
|
|
result = @cache.write('foo', 'bar')
|
|
|
|
assert_equal 'bar', @cache.read('foo') # make sure 'foo' was written
|
|
|
|
assert result
|
2014-01-08 18:48:19 -05:00
|
|
|
[200, {}, []]
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
}
|
|
|
|
app = @cache.middleware.new(app)
|
|
|
|
app.call({})
|
|
|
|
end
|
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
2012-11-16 19:05:53 -05:00
|
|
|
module AutoloadingCacheBehavior
|
2013-03-12 01:03:32 -04:00
|
|
|
include DependenciesTestHelpers
|
2012-11-16 19:05:53 -05:00
|
|
|
def test_simple_autoloading
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
@cache.write('foo', E.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
remove_constants(:E)
|
|
|
|
ActiveSupport::Dependencies.clear
|
|
|
|
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
assert_kind_of E, @cache.read('foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
remove_constants(:E)
|
|
|
|
ActiveSupport::Dependencies.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_two_classes_autoloading
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
@cache.write('foo', [E.new, ClassFolder.new])
|
|
|
|
end
|
|
|
|
|
|
|
|
remove_constants(:E, :ClassFolder)
|
|
|
|
ActiveSupport::Dependencies.clear
|
|
|
|
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
loaded = @cache.read('foo')
|
|
|
|
assert_kind_of Array, loaded
|
|
|
|
assert_equal 2, loaded.size
|
|
|
|
assert_kind_of E, loaded[0]
|
|
|
|
assert_kind_of ClassFolder, loaded[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
remove_constants(:E, :ClassFolder)
|
|
|
|
ActiveSupport::Dependencies.clear
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
class FileStoreTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
Dir.mkdir(cache_dir) unless File.exist?(cache_dir)
|
|
|
|
@cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
|
|
|
|
@peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
|
2011-07-23 16:57:04 -04:00
|
|
|
@cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), :expires_in => 60)
|
2012-02-22 06:19:05 -05:00
|
|
|
|
|
|
|
@buffer = StringIO.new
|
|
|
|
@cache.logger = ActiveSupport::Logger.new(@buffer)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
FileUtils.rm_r(cache_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache_dir
|
|
|
|
File.join(Dir.pwd, 'tmp_cache')
|
|
|
|
end
|
|
|
|
|
|
|
|
include CacheStoreBehavior
|
|
|
|
include LocalCacheBehavior
|
|
|
|
include CacheDeleteMatchedBehavior
|
|
|
|
include CacheIncrementDecrementBehavior
|
2012-11-16 19:05:53 -05:00
|
|
|
include AutoloadingCacheBehavior
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
|
2012-01-12 21:14:11 -05:00
|
|
|
def test_clear
|
|
|
|
filepath = File.join(cache_dir, ".gitkeep")
|
|
|
|
FileUtils.touch(filepath)
|
|
|
|
@cache.clear
|
|
|
|
assert File.exist?(filepath)
|
|
|
|
end
|
|
|
|
|
2010-11-07 17:01:18 -05:00
|
|
|
def test_key_transformation
|
|
|
|
key = @cache.send(:key_file_path, "views/index?id=1")
|
|
|
|
assert_equal "views/index?id=1", @cache.send(:file_path_key, key)
|
|
|
|
end
|
2011-07-23 16:57:04 -04:00
|
|
|
|
|
|
|
def test_key_transformation_with_pathname
|
|
|
|
FileUtils.touch(File.join(cache_dir, "foo"))
|
|
|
|
key = @cache_with_pathname.send(:key_file_path, "views/index?id=1")
|
|
|
|
assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key)
|
|
|
|
end
|
2011-12-12 14:40:29 -05:00
|
|
|
|
2012-10-23 03:04:42 -04:00
|
|
|
# Test that generated cache keys are short enough to have Tempfile stuff added to them and
|
2012-02-06 12:03:26 -05:00
|
|
|
# remain valid
|
|
|
|
def test_filename_max_size
|
|
|
|
key = "#{'A' * ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}"
|
|
|
|
path = @cache.send(:key_file_path, key)
|
|
|
|
Dir::Tmpname.create(path) do |tmpname, n, opts|
|
2012-03-31 07:01:07 -04:00
|
|
|
assert File.basename(tmpname+'.lock').length <= 255, "Temp filename too long: #{File.basename(tmpname+'.lock').length}"
|
2012-02-06 12:03:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-22 00:00:46 -04:00
|
|
|
# Because file systems have a maximum filename size, filenames > max size should be split in to directories
|
|
|
|
# If filename is 'AAAAB', where max size is 4, the returned path should be AAAA/B
|
|
|
|
def test_key_transformation_max_filename_size
|
|
|
|
key = "#{'A' * ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}B"
|
2011-12-12 14:40:29 -05:00
|
|
|
path = @cache.send(:key_file_path, key)
|
2011-09-22 00:00:46 -04:00
|
|
|
assert path.split('/').all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}
|
|
|
|
assert_equal 'B', File.basename(path)
|
|
|
|
end
|
2011-09-29 21:59:40 -04:00
|
|
|
|
2011-10-02 04:39:52 -04:00
|
|
|
# If nothing has been stored in the cache, there is a chance the cache directory does not yet exist
|
|
|
|
# Ensure delete_matched gracefully handles this case
|
|
|
|
def test_delete_matched_when_cache_directory_does_not_exist
|
|
|
|
assert_nothing_raised(Exception) do
|
|
|
|
ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/)
|
2011-09-29 21:59:40 -04:00
|
|
|
end
|
|
|
|
end
|
2012-02-22 06:19:05 -05:00
|
|
|
|
2013-02-18 19:37:48 -05:00
|
|
|
def test_delete_does_not_delete_empty_parent_dir
|
|
|
|
sub_cache_dir = File.join(cache_dir, 'subdir/')
|
|
|
|
sub_cache_store = ActiveSupport::Cache::FileStore.new(sub_cache_dir)
|
|
|
|
assert_nothing_raised(Exception) do
|
|
|
|
assert sub_cache_store.write('foo', 'bar')
|
|
|
|
assert sub_cache_store.delete('foo')
|
|
|
|
end
|
|
|
|
assert File.exist?(cache_dir), "Parent of top level cache dir was deleted!"
|
|
|
|
assert File.exist?(sub_cache_dir), "Top level cache dir was deleted!"
|
|
|
|
assert Dir.entries(sub_cache_dir).reject {|f| ActiveSupport::Cache::FileStore::EXCLUDED_DIRS.include?(f)}.empty?
|
|
|
|
end
|
|
|
|
|
2012-02-22 06:19:05 -05:00
|
|
|
def test_log_exception_when_cache_read_fails
|
|
|
|
File.expects(:exist?).raises(StandardError, "failed")
|
|
|
|
@cache.send(:read_entry, "winston", {})
|
2013-01-05 11:59:36 -05:00
|
|
|
assert @buffer.string.present?
|
2012-02-22 06:19:05 -05:00
|
|
|
end
|
2013-09-11 08:24:50 -04:00
|
|
|
|
|
|
|
def test_cleanup_removes_all_expired_entries
|
|
|
|
time = Time.now
|
|
|
|
@cache.write('foo', 'bar', expires_in: 10)
|
|
|
|
@cache.write('baz', 'qux')
|
|
|
|
@cache.write('quux', 'corge', expires_in: 20)
|
|
|
|
Time.stubs(:now).returns(time + 15)
|
|
|
|
@cache.cleanup
|
|
|
|
assert_not @cache.exist?('foo')
|
|
|
|
assert @cache.exist?('baz')
|
|
|
|
assert @cache.exist?('quux')
|
|
|
|
end
|
2013-10-28 17:09:22 -04:00
|
|
|
|
2013-08-06 22:43:28 -04:00
|
|
|
def test_write_with_unless_exist
|
|
|
|
assert_equal true, @cache.write(1, "aaaaaaaaaa")
|
|
|
|
assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
|
|
|
|
@cache.write(1, nil)
|
|
|
|
assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
|
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-01-15 22:28:10 -05:00
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
class MemoryStoreTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
2013-07-20 23:08:06 -04:00
|
|
|
@record_size = ActiveSupport::Cache.lookup_store(:memory_store).send(:cached_size, 1, ActiveSupport::Cache::Entry.new("aaaaaaaaaa"))
|
|
|
|
@cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10 + 1)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
include CacheStoreBehavior
|
|
|
|
include CacheDeleteMatchedBehavior
|
|
|
|
include CacheIncrementDecrementBehavior
|
|
|
|
|
|
|
|
def test_prune_size
|
|
|
|
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
|
|
|
@cache.write(2, "bbbbbbbbbb") && sleep(0.001)
|
|
|
|
@cache.write(3, "cccccccccc") && sleep(0.001)
|
|
|
|
@cache.write(4, "dddddddddd") && sleep(0.001)
|
|
|
|
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
|
|
|
@cache.read(2) && sleep(0.001)
|
|
|
|
@cache.read(4)
|
2011-07-29 18:27:45 -04:00
|
|
|
@cache.prune(@record_size * 3)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?(5)
|
|
|
|
assert @cache.exist?(4)
|
2012-09-30 14:08:11 -04:00
|
|
|
assert !@cache.exist?(3), "no entry"
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?(2)
|
2012-09-30 14:08:11 -04:00
|
|
|
assert !@cache.exist?(1), "no entry"
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_prune_size_on_write
|
|
|
|
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
|
|
|
@cache.write(2, "bbbbbbbbbb") && sleep(0.001)
|
|
|
|
@cache.write(3, "cccccccccc") && sleep(0.001)
|
|
|
|
@cache.write(4, "dddddddddd") && sleep(0.001)
|
|
|
|
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
|
|
|
@cache.write(6, "ffffffffff") && sleep(0.001)
|
|
|
|
@cache.write(7, "gggggggggg") && sleep(0.001)
|
|
|
|
@cache.write(8, "hhhhhhhhhh") && sleep(0.001)
|
|
|
|
@cache.write(9, "iiiiiiiiii") && sleep(0.001)
|
|
|
|
@cache.write(10, "kkkkkkkkkk") && sleep(0.001)
|
|
|
|
@cache.read(2) && sleep(0.001)
|
|
|
|
@cache.read(4) && sleep(0.001)
|
|
|
|
@cache.write(11, "llllllllll")
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?(11)
|
|
|
|
assert @cache.exist?(10)
|
|
|
|
assert @cache.exist?(9)
|
|
|
|
assert @cache.exist?(8)
|
|
|
|
assert @cache.exist?(7)
|
2012-09-30 15:37:59 -04:00
|
|
|
assert !@cache.exist?(6), "no entry"
|
|
|
|
assert !@cache.exist?(5), "no entry"
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?(4)
|
2012-09-30 15:37:59 -04:00
|
|
|
assert !@cache.exist?(3), "no entry"
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?(2)
|
2012-09-30 15:37:59 -04:00
|
|
|
assert !@cache.exist?(1), "no entry"
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
2013-07-20 23:08:06 -04:00
|
|
|
def test_prune_size_on_write_based_on_key_length
|
|
|
|
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
|
|
|
@cache.write(2, "bbbbbbbbbb") && sleep(0.001)
|
|
|
|
@cache.write(3, "cccccccccc") && sleep(0.001)
|
|
|
|
@cache.write(4, "dddddddddd") && sleep(0.001)
|
|
|
|
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
|
|
|
@cache.write(6, "ffffffffff") && sleep(0.001)
|
|
|
|
@cache.write(7, "gggggggggg") && sleep(0.001)
|
|
|
|
@cache.write(8, "hhhhhhhhhh") && sleep(0.001)
|
|
|
|
@cache.write(9, "iiiiiiiiii") && sleep(0.001)
|
|
|
|
long_key = '*' * 2 * @record_size
|
|
|
|
@cache.write(long_key, "llllllllll")
|
|
|
|
assert @cache.exist?(long_key)
|
|
|
|
assert @cache.exist?(9)
|
|
|
|
assert @cache.exist?(8)
|
|
|
|
assert @cache.exist?(7)
|
|
|
|
assert @cache.exist?(6)
|
|
|
|
assert !@cache.exist?(5), "no entry"
|
|
|
|
assert !@cache.exist?(4), "no entry"
|
|
|
|
assert !@cache.exist?(3), "no entry"
|
|
|
|
assert !@cache.exist?(2), "no entry"
|
|
|
|
assert !@cache.exist?(1), "no entry"
|
|
|
|
end
|
|
|
|
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
def test_pruning_is_capped_at_a_max_time
|
|
|
|
def @cache.delete_entry (*args)
|
|
|
|
sleep(0.01)
|
|
|
|
super
|
2009-02-02 19:43:14 -05:00
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
|
|
|
@cache.write(2, "bbbbbbbbbb") && sleep(0.001)
|
|
|
|
@cache.write(3, "cccccccccc") && sleep(0.001)
|
|
|
|
@cache.write(4, "dddddddddd") && sleep(0.001)
|
|
|
|
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
|
|
|
@cache.prune(30, 0.001)
|
2011-11-21 17:22:02 -05:00
|
|
|
assert @cache.exist?(5)
|
|
|
|
assert @cache.exist?(4)
|
|
|
|
assert @cache.exist?(3)
|
|
|
|
assert @cache.exist?(2)
|
|
|
|
assert !@cache.exist?(1)
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2012-05-10 11:19:45 -04:00
|
|
|
|
|
|
|
def test_write_with_unless_exist
|
|
|
|
assert_equal true, @cache.write(1, "aaaaaaaaaa")
|
|
|
|
assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true)
|
|
|
|
@cache.write(1, nil)
|
|
|
|
assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true)
|
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
2009-02-02 19:43:14 -05:00
|
|
|
|
2012-08-22 18:42:39 -04:00
|
|
|
class MemCacheStoreTest < ActiveSupport::TestCase
|
|
|
|
require 'dalli'
|
|
|
|
|
|
|
|
begin
|
|
|
|
ss = Dalli::Client.new('localhost:11211').stats
|
|
|
|
raise Dalli::DalliError unless ss['localhost:11211']
|
|
|
|
|
|
|
|
MEMCACHE_UP = true
|
|
|
|
rescue Dalli::DalliError
|
|
|
|
$stderr.puts "Skipping memcached tests. Start memcached and try again."
|
|
|
|
MEMCACHE_UP = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
skip "memcache server is not up" unless MEMCACHE_UP
|
|
|
|
|
|
|
|
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60)
|
|
|
|
@peek = ActiveSupport::Cache.lookup_store(:mem_cache_store)
|
|
|
|
@data = @cache.instance_variable_get(:@data)
|
|
|
|
@cache.clear
|
|
|
|
@cache.silence!
|
|
|
|
@cache.logger = ActiveSupport::Logger.new("/dev/null")
|
|
|
|
end
|
|
|
|
|
|
|
|
include CacheStoreBehavior
|
|
|
|
include LocalCacheBehavior
|
|
|
|
include CacheIncrementDecrementBehavior
|
|
|
|
include EncodedKeyCacheBehavior
|
2012-11-16 19:05:53 -05:00
|
|
|
include AutoloadingCacheBehavior
|
2012-08-22 18:42:39 -04:00
|
|
|
|
|
|
|
def test_raw_values
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
|
|
|
cache.clear
|
|
|
|
cache.write("foo", 2)
|
|
|
|
assert_equal "2", cache.read("foo")
|
|
|
|
end
|
2009-07-01 19:56:43 -04:00
|
|
|
|
2012-08-22 18:42:39 -04:00
|
|
|
def test_raw_values_with_marshal
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
|
|
|
cache.clear
|
|
|
|
cache.write("foo", Marshal.dump([]))
|
|
|
|
assert_equal [], cache.read("foo")
|
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
|
2012-08-22 18:42:39 -04:00
|
|
|
def test_local_cache_raw_values
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
|
|
|
cache.clear
|
|
|
|
cache.with_local_cache do
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
cache.write("foo", 2)
|
|
|
|
assert_equal "2", cache.read("foo")
|
2009-07-01 19:56:43 -04:00
|
|
|
end
|
2012-08-22 18:42:39 -04:00
|
|
|
end
|
2011-12-12 14:40:29 -05:00
|
|
|
|
2012-08-22 18:42:39 -04:00
|
|
|
def test_local_cache_raw_values_with_marshal
|
|
|
|
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
|
|
|
cache.clear
|
|
|
|
cache.with_local_cache do
|
2011-06-09 13:15:37 -04:00
|
|
|
cache.write("foo", Marshal.dump([]))
|
2011-12-12 14:40:29 -05:00
|
|
|
assert_equal [], cache.read("foo")
|
2011-06-09 13:15:37 -04:00
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
2012-09-30 12:26:04 -04:00
|
|
|
|
|
|
|
def test_read_should_return_a_different_object_id_each_time_it_is_called
|
|
|
|
@cache.write('foo', 'bar')
|
|
|
|
assert_not_equal @cache.read('foo').object_id, @cache.read('foo').object_id
|
|
|
|
value = @cache.read('foo')
|
|
|
|
value << 'bingo'
|
|
|
|
assert_not_equal value, @cache.read('foo')
|
|
|
|
end
|
2008-10-09 11:37:28 -04:00
|
|
|
end
|
2009-10-09 10:03:18 -04:00
|
|
|
|
2011-12-12 14:40:29 -05:00
|
|
|
class NullStoreTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@cache = ActiveSupport::Cache.lookup_store(:null_store)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_clear
|
|
|
|
@cache.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cleanup
|
|
|
|
@cache.cleanup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_write
|
|
|
|
assert_equal true, @cache.write("name", "value")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read
|
|
|
|
@cache.write("name", "value")
|
|
|
|
assert_nil @cache.read("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete
|
|
|
|
@cache.write("name", "value")
|
|
|
|
assert_equal false, @cache.delete("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_increment
|
|
|
|
@cache.write("name", 1, :raw => true)
|
|
|
|
assert_nil @cache.increment("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_decrement
|
|
|
|
@cache.write("name", 1, :raw => true)
|
|
|
|
assert_nil @cache.increment("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_matched
|
|
|
|
@cache.write("name", "value")
|
|
|
|
@cache.delete_matched(/name/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_local_store_strategy
|
|
|
|
@cache.with_local_cache do
|
|
|
|
@cache.write("name", "value")
|
|
|
|
assert_equal "value", @cache.read("name")
|
|
|
|
@cache.delete("name")
|
|
|
|
assert_nil @cache.read("name")
|
|
|
|
@cache.write("name", "value")
|
|
|
|
end
|
|
|
|
assert_nil @cache.read("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_setting_nil_cache_store
|
|
|
|
assert ActiveSupport::Cache.lookup_store.class.name, ActiveSupport::Cache::NullStore.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-09 10:03:18 -04:00
|
|
|
class CacheStoreLoggerTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
|
|
|
|
|
|
|
|
@buffer = StringIO.new
|
2012-01-04 13:52:24 -05:00
|
|
|
@cache.logger = ActiveSupport::Logger.new(@buffer)
|
2009-10-09 10:03:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_logging
|
|
|
|
@cache.fetch('foo') { 'bar' }
|
2013-01-05 11:59:36 -05:00
|
|
|
assert @buffer.string.present?
|
2009-10-09 10:03:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mute_logging
|
|
|
|
@cache.mute { @cache.fetch('foo') { 'bar' } }
|
2013-01-05 11:59:36 -05:00
|
|
|
assert @buffer.string.blank?
|
2009-10-09 10:03:18 -04:00
|
|
|
end
|
|
|
|
end
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
|
|
|
|
class CacheEntryTest < ActiveSupport::TestCase
|
|
|
|
def test_expired
|
|
|
|
entry = ActiveSupport::Cache::Entry.new("value")
|
2011-03-07 12:36:07 -05:00
|
|
|
assert !entry.expired?, 'entry not expired'
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
entry = ActiveSupport::Cache::Entry.new("value", :expires_in => 60)
|
2011-03-07 12:36:07 -05:00
|
|
|
assert !entry.expired?, 'entry not expired'
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
time = Time.now + 61
|
|
|
|
Time.stubs(:now).returns(time)
|
2011-03-07 12:36:07 -05:00
|
|
|
assert entry.expired?, 'entry is expired'
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_compress_values
|
2012-09-30 12:26:04 -04:00
|
|
|
value = "value" * 100
|
|
|
|
entry = ActiveSupport::Cache::Entry.new(value, :compress => true, :compress_threshold => 1)
|
|
|
|
assert_equal value, entry.value
|
2012-10-01 06:50:36 -04:00
|
|
|
assert(value.bytesize > entry.size, "value is compressed")
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_non_compress_values
|
2012-09-30 12:26:04 -04:00
|
|
|
value = "value" * 100
|
|
|
|
entry = ActiveSupport::Cache::Entry.new(value)
|
|
|
|
assert_equal value, entry.value
|
|
|
|
assert_equal value.bytesize, entry.size
|
|
|
|
end
|
|
|
|
|
2013-04-16 13:18:52 -04:00
|
|
|
def test_restoring_version_4beta1_entries
|
|
|
|
version_4beta1_entry = ActiveSupport::Cache::Entry.allocate
|
|
|
|
version_4beta1_entry.instance_variable_set(:@v, "hello")
|
|
|
|
version_4beta1_entry.instance_variable_set(:@x, Time.now.to_i + 60)
|
|
|
|
entry = Marshal.load(Marshal.dump(version_4beta1_entry))
|
2012-09-30 12:26:04 -04:00
|
|
|
assert_equal "hello", entry.value
|
|
|
|
assert_equal false, entry.expired?
|
|
|
|
end
|
|
|
|
|
2013-04-16 13:18:52 -04:00
|
|
|
def test_restoring_compressed_version_4beta1_entries
|
|
|
|
version_4beta1_entry = ActiveSupport::Cache::Entry.allocate
|
|
|
|
version_4beta1_entry.instance_variable_set(:@v, Zlib::Deflate.deflate(Marshal.dump("hello")))
|
|
|
|
version_4beta1_entry.instance_variable_set(:@c, true)
|
|
|
|
entry = Marshal.load(Marshal.dump(version_4beta1_entry))
|
2012-09-30 12:26:04 -04:00
|
|
|
assert_equal "hello", entry.value
|
|
|
|
end
|
|
|
|
|
2013-04-16 13:18:52 -04:00
|
|
|
def test_restoring_expired_version_4beta1_entries
|
|
|
|
version_4beta1_entry = ActiveSupport::Cache::Entry.allocate
|
|
|
|
version_4beta1_entry.instance_variable_set(:@v, "hello")
|
|
|
|
version_4beta1_entry.instance_variable_set(:@x, Time.now.to_i - 1)
|
|
|
|
entry = Marshal.load(Marshal.dump(version_4beta1_entry))
|
2012-09-30 12:26:04 -04:00
|
|
|
assert_equal "hello", entry.value
|
|
|
|
assert_equal true, entry.expired?
|
ActiveSupport::Cache refactoring
All Caches
* Add default options to initializer that will be sent to all read, write, fetch, exist?, increment, and decrement
* Add support for the :expires_in option to fetch and write for all caches. Cache entries are stored with the create timestamp and a ttl so that expiration can be handled independently of the implementation.
* Add support for a :namespace option. This can be used to set a global prefix for cache entries.
* Deprecate expand_cache_key on ActiveSupport::Cache and move it to ActionController::Caching and ActionDispatch::Http::Cache since the logic in the method used some Rails specific environment variables and was only used by ActionPack classes. Not very DRY but there didn't seem to be a good shared spot and ActiveSupport really shouldn't be Rails specific.
* Add support for :race_condition_ttl to fetch. This setting can prevent race conditions on fetch calls where several processes try to regenerate a recently expired entry at once.
* Add support for :compress option to fetch and write which will compress any data over a configurable threshold.
* Nil values can now be stored in the cache and are distinct from cache misses for fetch.
* Easier API to create new implementations. Just need to implement the methods read_entry, write_entry, and delete_entry instead of overwriting existing methods.
* Since all cache implementations support storing objects, update the docs to state that ActiveCache::Cache::Store implementations should store objects. Keys, however, must be strings since some implementations require that.
* Increase test coverage.
* Document methods which are provided as convenience but which may not be universally available.
MemoryStore
* MemoryStore can now safely be used as the cache for single server sites.
* Make thread safe so that the default cache implementation used by Rails is thread safe. The overhead is minimal and it is still the fastest store available.
* Provide :size initialization option indicating the maximum size of the cache in memory (defaults to 32Mb).
* Add prune logic that removes the least recently used cache entries to keep the cache size from exceeding the max.
* Deprecated SynchronizedMemoryStore since it isn't needed anymore.
FileStore
* Escape key values so they will work as file names on all file systems, be consistent, and case sensitive
* Use a hash algorithm to segment the cache into sub directories so that a large cache doesn't exceed file system limits.
* FileStore can be slow so implement the LocalCache strategy to cache reads for the duration of a request.
* Add cleanup method to keep the disk from filling up with expired entries.
* Fix increment and decrement to use file system locks so they are consistent between processes.
MemCacheStore
* Support all keys. Previously keys with spaces in them would fail
* Deprecate CompressedMemCacheStore since it isn't needed anymore (use :compress => true)
[#4452 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-22 00:22:05 -04:00
|
|
|
end
|
|
|
|
end
|