跳至內文 跳至搜尋

檔案快取儲存庫

快取儲存庫實作,可將所有資料儲存在檔案系統中。

方法
C
D
I
N
S

常數

目錄格式化程式 = "%03X"
 
檔名最大大小 = 226
 
檔案路徑最大大小 = 900
 
快取檔案 = [".gitkeep", ".keep"].freeze
 

屬性

[R] 快取路徑

類別公開方法

new(cache_path, **options)

# File activesupport/lib/active_support/cache/file_store.rb, line 20
def initialize(cache_path, **options)
  super(options)
  @cache_path = cache_path.to_s
end

supports_cache_versioning?()

公告支援快取版本控制。

# File activesupport/lib/active_support/cache/file_store.rb, line 26
def self.supports_cache_versioning?
  true
end

執行個體公開方法

清理(options = nil)

預先對所有已儲存金鑰進行迭代,並移除過期的金鑰。

# File activesupport/lib/active_support/cache/file_store.rb, line 40
def cleanup(options = nil)
  options = merged_options(options)
  search_dir(cache_path) do |fname|
    entry = read_entry(fname, **options)
    delete_entry(fname, **options) if entry && entry.expired?
  end
end

清除(options = nil)

從快取中刪除所有項目。在這種情況下,它會刪除,指定檔案儲存庫目錄中,除了 .keep 或 .gitkeep 以外的所有輸入。小心使用 FileStore 時,組態檔案中指定的目錄,因為目錄中的所有項目都會被刪除。

# File activesupport/lib/active_support/cache/file_store.rb, line 33
def clear(options = nil)
  root_dirs = (Dir.children(cache_path) - GITKEEP_FILES)
  FileUtils.rm_r(root_dirs.collect { |f| File.join(cache_path, f) })
rescue Errno::ENOENT, Errno::ENOTEMPTY
end

遞減(name, amount = 1, options = nil)

遞減快取整數值。傳回更新後的數值。

若金鑰尚未設定,會將其設定為 -amount

cache.decrement("foo") # => -1

若要設定特定數值,請呼叫 write

cache.write("baz", 5)
cache.decrement("baz") # => 4
# File activesupport/lib/active_support/cache/file_store.rb, line 80
def decrement(name, amount = 1, options = nil)
  options = merged_options(options)
  key = normalize_key(name, options)

  instrument(:decrement, key, amount: amount) do
    modify_value(name, -amount, options)
  end
end

increment(名稱, 金額 = 1, 選項 = nil)

增加快取整數數值。傳回更新後的數值。

如果沒有設定金鑰,則從 0 開始

cache.increment("foo") # => 1
cache.increment("bar", 100) # => 100

若要設定特定數值,請呼叫 write

cache.write("baz", 5)
cache.increment("baz") # => 6
# File activesupport/lib/active_support/cache/file_store.rb, line 60
def increment(name, amount = 1, options = nil)
  options = merged_options(options)
  key = normalize_key(name, options)

  instrument(:increment, key, amount: amount) do
    modify_value(name, amount, options)
  end
end