-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: cache Available
results to reduce network io
#240
Conversation
|
Agreed, but this can be enhanced later, for now it can be done with the
The cache is invalidated only in the following cases: vfox config cache.availableHookDuration 0
vfox config cache.availableHookDuration -1 In addition, there seems to be an issue with |
and we also can provide a cache library for the plugins, let them can store some data. local cache = require("vfox/cache")
local key = "nodejs-index-json"
local hit = cache.has(key)
if (!hit) then
local data = -- fetch --
cache.set(key, data, 12 * 60 * 60 * 1000)
end
Sorry, I accidentally clicked the close button. |
Sure. I have this plan. |
Oops, thanks for point out. Let me think about how to deal with it. |
You can try adding the following code func (c *Cache) UnmarshalYAML(node *yaml.Node) error {
var data map[string]any
err := node.Decode(&data)
if err != nil {
return err
}
if v, ok := data["availableHookDuration"]; ok {
switch va := v.(type) {
case int:
c.AvailableHookDuration = time.Duration(va)
case string:
c.AvailableHookDuration, err = time.ParseDuration(va)
if err != nil {
return err
}
}
}
return nil
} Or type Cache struct {
AvailableHookDuration VfoxDuration `yaml:"availableHookDuration"` // Available hook result cache time
}
type VfoxDuration time.Duration
func (c *VfoxDuration) UnmarshalYAML(node *yaml.Node) error {
var data any
err := node.Decode(&data)
if err != nil {
return err
}
switch va := data.(type) {
case int:
*c = VfoxDuration(va)
case string:
pd, err := time.ParseDuration(va)
if err != nil {
return err
}
*c = VfoxDuration(pd)
}
return nil
} The second option adds a new type |
I took your second option. ; ) |
// wrap Available hook with Cache. | ||
if source.HasFunction("Available") { | ||
targetHook := PLUGIN.RawGetString("Available") | ||
source.pluginObj.RawSetString("Available", vm.Instance.NewFunction(func(L *lua.LState) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来可以把这个 hook 的能力做到 LuaVM 里,
一个初始的想法是这样的:
vm.DecorateFunction(func, func () int {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好主意! 可以放到下一版本去做. 目前先保证功能优先.
Hi, Can you push your changes? |
vfox
calls or calls within the plugin.see #227 (comment)