如何刷新缓存 [英] How to flush the cache

查看:108
本文介绍了如何刷新缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apps脚本中,我需要一种无论密钥如何刷新缓存的方法。或者我需要一种方法来查找所有当前缓存的密钥。

In Apps Script I need a way to flush the cache regardless of key. Alternatively I need a way to find all the keys which are currently cached.

当我们缓存项目时,我们会根据一些动态属性创建密钥,所以我们不能请确保在任何时候缓存中的密钥。

When we cache items we create the key based on a number of dynamic properties so we can't be sure what keys are in the cache at any one time.

有没有办法在AppsScript中执行上述任一操作?我是否需要将密钥写出到某处的日志中,然后当我想要刷新它时,只需删除已保存的所有密钥列表中的所有密钥?

Is there a way to do either of the above in AppsScript? Do I need to write out my keys to a log somewhere and then when I want to flush it just do remove all on my saved list of keys?

我看过在这里的文档: https://developers.google.com/apps-脚本/参考/缓存/缓存服务,但找不到任何东西,所以我不太满意。

I've looked at the documentation here: https://developers.google.com/apps-script/reference/cache/cache-service but can't find anything so I'm not too hopeful.

只是想知道其他人是否有解决方案了解缓存中的密钥是什么?

Just wondered if anyone else has a solution for knowing what keys are in the cache?

推荐答案

没办法这样做。让缓存失效的更好方法是在每个缓存对象中存储一个版本,并将版本保存在scriptProperties中。
每当您从缓存中读取时,如果其版本低于scriptproperties中的全局版本,则忽略它。
要使缓存无效,只需从scriptProperties中增加版本。

No way to do it like that. A better way to invalidate the cache is to store a version inside each cached object and keep the version in scriptProperties too. Whenever you read from the cache ignore it if its version is lower than your global version from scriptproperties. To invalidate the cache(s) simply increment your version from scriptProperties.

这篇关于如何刷新缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆