Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

feat: Consider adding motion (.mtn) cache / 考虑加上动作缓存 #4

Closed
1 task done
CDog34 opened this issue Feb 24, 2018 · 5 comments
Closed
1 task done
Projects

Comments

@CDog34
Copy link

CDog34 commented Feb 24, 2018

Expected behavior 预期行为

Network request should only be make when requiring a certain .mtn file for the first time. And the same file should be loaded from cache for subsequent requests.
当且仅当第一次请求某个动作文件时发出网络请求。后续对同一个文件的请求应该从缓存中获取。

Actual behavior 实际行为

Network requests are made each time requiring the same .mtn file.
请求同一个 .mtn 文件会发送多个网络请求。
default

Steps to reproduce the behavior 复现步骤

config / 配置如下:

live2d:
  enable: true
  scriptFrom: local
  model:
    use: local-model
  display:
    position: right
    width: 125
    height: 250
    hOffset: 50
  mobile:
    show: false
  react:
    opacityDefault: 1

P.S. Actually, I'm using the hexo-helper-live2d plugin. But, I think it should be a issue for this repo. / 实际上,我是用的是 hexo-helper-live2d 插件,但是我认为这应该是这个仓库的模块的问题。

@EYHN @xiazeyu

@xiazeyu
Copy link
Owner

xiazeyu commented Feb 25, 2018

@CDog34
是的。这是缓存的问题。
我的想法是增加一个modelHash字段,用来标识模型的版本。然后根据modelHash与本地缓存比较,判断是直接加载缓存还是下载新版本。
由于模型json,mtn是XHttpRequest的,估计只能使用localStorage了。

目测这个功能会在4.0被加入。

@CDog34
Copy link
Author

CDog34 commented Feb 25, 2018

感谢回复。
其实我的想法是:维护一个运行时缓存,在同一个生命周期内根据 URL 来判断是从缓存中取还是发网络请求,刷新页面后缓存清空。所以我感觉只要弄一个简单的内存缓存就可以满足我的需要了~其实主要还是觉得如果用户在页面上长时间停留,重复请求相同内容有点伤...

@xiazeyu
Copy link
Owner

xiazeyu commented Feb 25, 2018

运行时缓存...貌似每个页面都是独立的js...就像开第二页时可能同样需要加载mtn和moc..
我的想法是用我上面提到的方法预载模型,达到同时缓存moc和mtn的目的..(loadBytes层面的最底层API)
简单的内存缓存...能否帮我测试新开页面moc会不会被重复加载,如果会的话我觉得我这种方案更好一些..

@xiazeyu
Copy link
Owner

xiazeyu commented Feb 25, 2018

因为相比mtn..moc更大显然更值得缓存

@xiazeyu
Copy link
Owner

xiazeyu commented Feb 25, 2018

http://blog.csdn.net/wangji163163/article/details/5726406
看起来浏览器会自动缓存...你看看你浏览器有没有什么设置问题..

@xiazeyu xiazeyu changed the title Consider adding motion (.mtn) cache / 考虑加上动作缓存 feat: Consider adding motion (.mtn) cache / 考虑加上动作缓存 Mar 18, 2018
@xiazeyu xiazeyu added this to To do in 4.0 Mar 18, 2018
@EYHN EYHN closed this as completed in a337ff7 Mar 31, 2019
4.0 automation moved this from To do to Done Mar 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
4.0
  
Done
Development

No branches or pull requests

2 participants