你現在尚未登錄,許多功能可能無法正常使用,若已有賬號,請登錄,若沒有,請先註冊Twitch賬號
目前我們有非常多的待翻譯條目,你也可以看一下目前我們需要優先處理的有哪些目前我們有非常多的待翻譯條目,你也可以看一下目前我們需要優先處理的有哪些英雄頁面的攻略、克制和物品頁面的推薦英雄、小貼士等均為社區玩家編寫的,你也可以把自己的心得寫上去哦。英雄頁面的攻略、克制和物品頁面的推薦英雄、小貼士等均為社區玩家編寫的,你也可以把自己的心得寫上去哦。看不懂bkb文本中debuff技能免疫之前施加並且沒有被驅散雪球戰鬥嚎叫是少數幾個不帶驅散的技能免疫,親自試一下戰鬥嚎叫過程中還有沒有debuff吧。看不懂bkb文本中debuff技能免疫之前施加並且沒有被驅散雪球戰鬥嚎叫是少數幾個不帶驅散的技能免疫,親自試一下戰鬥嚎叫過程中還有沒有debuff吧。看不懂技能的buff/debuff是哪個跟哪個?鼠標移動到名稱上就能看到遊戲內顯示的名字了。看不懂技能的buff/debuff是哪個跟哪個?鼠標移動到名稱上就能看到遊戲內顯示的名字了。

模块:Cache/doc

来自Dota 2 Wiki
跳转至: 导航搜索

这是模块:Cache的文档页面

This module provides a way of storing data between module invocations. Possible data types are strings, numbers, nil and tables. This is useful for templates that tend to appear multiple times on the same page. Do not use this for modules that only appear a single time per page. It will lead to performance decreases.

Warning[编辑]

Metatables are not preserved. To work around this, this module automatically checks for a __tostring method and converts the table to a string if possible.

Functions[编辑]

Basic[编辑]

cache.auto[编辑]

cache.auto(func, args, prefix)

The cache.auto function is the simplest way of implementing caching. It wraps the function supplying the value and automatically decides whether to execute the function or use a cached version.


It's parameters are:

  1. The function for which caching should be applied.
  2. A table holding the functions arguments.
  3. An optional prefix for the key under which the output will be stored (useful if multiple functions have the same arguments).

In pseudo-code it would look something like this:

function cache.auto(func, args, prefix)
  if prefix_args[1]_args[2].isCached() then
    return get_cache(prefix_args[1]_args[2])
  else
    return set_cache(prefix_args[1]_args[2], func(args))
  end
end

Advanced[编辑]

Use these functions if you want to manually implement caching in your module.

cache.set[编辑]

cache.set(args, value, prefix)

Stores content. Logs the stored content and the variable name. Returns the content.

cache.get[编辑]

cache.get(args, prefix)

Retrieves content. Returns the content.

Usage[编辑]

local p = {}
local cache = require('Module:Cache')


function p.example(args)
  -- First usage of p._example(); Executes the function and stores the value.
  cache.auto(p._example, args, 'example_prefix')

  -- Second usage; Uses the cached version.
  cache.auto(p._example, args, 'example_prefix')
end

function p._example(args)
  return args[1]
end


return p

Tests[编辑]

YesY All tests passed.

Name Expected Actual
YesY test_auto_boolean
YesY test_auto_number
YesY test_auto_string
YesY test_auto_table
YesY test_get_boolean
YesY test_get_no_set
YesY test_get_number
YesY test_get_string
YesY test_get_table
YesY test_set_boolean
YesY test_set_number
YesY test_set_string
YesY test_set_table