ASimpleCache
ASimpleCache copied to clipboard
a simple cache for android and java
不同值,但是却同一个 hashCod)的,亲自验证过的
清除缓存的问题
调用cache.clear()方法后,不能重新创建ACache目录
代码优化建议
` //private static Map mInstanceMap = Collections.synchronizedMap(new HashMap()); private static ACache instance = null; /** * 个人觉得没必要用map来缓存实例,一个就够用了 * @param cacheDir * @param max_zise * @param max_count * @return */ public...
昨天发现NumberFormatException这个异常,定位到判断时候过期的判断,但是缓存的数据并没有设置过期时间,但是刚好缓存的数据包含‘-’,查看那一段代码,是截取前13位字符,判断是不是时间的,然后转化为时间的,所以这里会有一个问题就是,极少数情况下,刚好string中包含,“-”,有同时满足后面有一个“ ”空格,就满足indexOf(data, mSeparator),这一个string就会被错认为一个包含过期时间的字段,然后转化时间就会报错,所以过期时间的判断有点不严谨,会有这种情况的出现,虽然很少很少,建议转化加一个try catch,可以解决
https://github.com/xufeifandj/Acache 我看有个这个作者把 File f = new File(ctx.getCacheDir(), "ACache"); 改为了File f = new File(ctx.getFilesDir(), cacheName); 然后在说明里写的是“xff轻量级数据存储 修改来自 Michael Yang ,修改缓存路径,防止数据被清空” 用ctx.getFilesDir()是会让缓存的数据更安全一些吗?
作者啊,这个项目是不是不在维护了。
private ACache(File cacheDir, long max_size, int max_count) { if (!cacheDir.exists() && !cacheDir.mkdirs()) { throw new RuntimeException("can't make dirs in " + cacheDir.getAbsolutePath()); } } 主要是一段代码
Is there any way to get expired caches and delete them?
二级缓存
目前均是disk cache,能否支持ram cache?