R 如何缓存任意R对象 How to cache R object in R

在 R studio 上运行R代码时,公共区域的变量会存在内存中且可以被全局访问 (私有代码块内的临时变量除外),这和Python很像,和静态语言如JAVA, C 很不一样。

R/python进行数据分析过程中,需要刻意用到缓存的场景倒不是很多,一般的公共区域变量全局访问就够用了。但在大一些的项目中,譬如我写了一个提供 动态生成models,计算统计指标,画图等APIs 的R服务器,这时候缓存一下请求结果,就不用每次重新计算了。

我尝试自己写个list,用key-value的形式模仿实现Java中的map,在服务器端却出现了奇怪的并发bug。。这里提供一个可以实现“缓存任意R对象”的R包。

With this package【1】, any R object can be cached in a key-value storage where the key can be an arbitrary set of R objects. The cache memory is persistent (on the file system).

清空缓存:getCacheRootPath()

 Gets the root path to the file cache directory

This directory structure was created by the R package 'R.cache'
available on CRAN [https://cran.r-project.org/package=R.cache].
It holds cache files containing results memoized by various
R packages that utilize the R.cache package.  It is safe to
delete all o

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Clark Kent 2000

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值