請見 ActiveSupport::Cache::Store
了解說明。
命名空間
- 模組 ActiveSupport::Cache::SerializerWithFallback
- 模組 ActiveSupport::Cache::Strategy
- 類別 ActiveSupport::Cache::Coder
- 類別 ActiveSupport::Cache::FileStore
- 類別 ActiveSupport::Cache::MemCacheStore
- 類別 ActiveSupport::Cache::MemoryStore
- 類別 ActiveSupport::Cache::NullStore
- 類別 ActiveSupport::Cache::RedisCacheStore
- 類別 ActiveSupport::Cache::Store
- 類別 ActiveSupport::Cache::WriteOptions
方法
常數
DEFAULT_COMPRESS_LIMIT | = | 1.kilobyte |
DeserializationError | = | Class.new(StandardError) |
快取項目無法解除序列化時,編碼器會引發這個錯誤。這個錯誤會當成快取遺漏來處理。 |
||
OPTION_ALIASES | = | { expires_in: [:expire_in, :expired_in] }.freeze |
通用選項名稱對應至儲存體將識別的別名。 |
||
UNIVERSAL_OPTIONS | = | [ :coder, :compress, :compress_threshold, :compressor, :expire_in, :expired_in, :expires_in, :namespace, :race_condition_ttl, :serializer, :skip_nil, ] |
這些選項適用於所有快取實作。個別的快取實作可能會支援其他選項。 |
屬性
[唯讀/寫入] | format_version |
類別公開方法
expand_cache_key(key, namespace = nil) 連結
將 key
參數展開成可供快取儲存體使用的金鑰。可選擇性的接受一個命名空間,且所有金鑰都將限制在該命名空間內。
如果提供的 key
參數是一個陣列或可以轉換成陣列,陣列中的每個元素都會轉換成參數/金鑰,並合併成一個單一的金鑰。例如
ActiveSupport::Cache.expand_cache_key([:foo, :bar]) # => "foo/bar"
ActiveSupport::Cache.expand_cache_key([:foo, :bar], "namespace") # => "namespace/foo/bar"
key
參數也可以回應 cache_key
或 to_param
。
資料來源: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/cache.rb, line 111 def expand_cache_key(key, namespace = nil) expanded_cache_key = namespace ? +"#{namespace}/" : +"" if prefix = ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"] expanded_cache_key << "#{prefix}/" end expanded_cache_key << retrieve_cache_key(key) expanded_cache_key end
lookup_store(store = nil, *parameters) 連結
根據指定選項,建立一個新的 Store
物件。
如果沒有將任何參數傳遞給這個方法,則會傳回一個新的 ActiveSupport::Cache::MemoryStore
物件。
如果您傳遞一個 符號
作為第一個參數,則會建立 ActiveSupport::Cache
名稱空間下的相對應快取儲存體類別。例如
ActiveSupport::Cache.lookup_store(:memory_store)
# => returns a new ActiveSupport::Cache::MemoryStore object
ActiveSupport::Cache.lookup_store(:mem_cache_store)
# => returns a new ActiveSupport::Cache::MemCacheStore object
任何其他參數都會傳遞給相對應的快取儲存體類別的建構函式
ActiveSupport::Cache.lookup_store(:file_store, '/tmp/cache')
# => same as: ActiveSupport::Cache::FileStore.new('/tmp/cache')
如果第一個參數不是 Symbol
,則它只會傳回
ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
# => returns MyOwnCacheStore.new
來源: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/cache.rb, line 85 def lookup_store(store = nil, *parameters) case store when Symbol options = parameters.extract_options! retrieve_store_class(store).new(*parameters, **options) when Array lookup_store(*store) when nil ActiveSupport::Cache::MemoryStore.new else store end end