首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏Android知识点总结

    4-SII--☆Android缓存文件(带有效时长)封装


    * 时间:2018/8/26 0026:6:20
    * 邮箱:1981462002@qq.com
    * 说明:缓存策略接口 */ public interface CacheStrategy br/> * 邮箱:1981462002@qq.com
    * 说明:文件缓存基类 */ public abstract class BaseFileStrategy implements CacheStrategy 缓存策略 */ public CacheWorker(CacheStrategy cacheStrategy) { mCacheStrategy = cacheStrategy 缓存策略 */ public void setCacheStrategy(CacheStrategy cacheStrategy) { mCacheStrategy = cacheStrategy; } }

    54320发布于 2018-09-26
  • 来自专栏liulun

    WinForm企业应用框架设计【五】系统登录以及身份验证+源码

    ; return; } CacheStrategy.CurUser = CurUser; DialogResult Guid.Empty : CacheStrategy.CurUser.Id; MessageHeader<Guid> mhg = new MessageHeader<Guid>( Guid.Empty : CacheStrategy.CurUser.Id;             MessageHeader<Guid> mhg = new MessageHeader<Guid>( CacheStrategy.HasKey(curId)) { throw new Exception("#请重新登录#"); return result; } } 因为登录的时候就不用再做验证了,所以我们的重写方法就没有任何代码 CacheStrategy.AddObject(result.Id, result

    99520编辑于 2022-05-09
  • 来自专栏Android 研究

    OKHttp源码解析(六)--中阶之缓存基础

    前面一节课主要讲解了interceptor及其调用链,本篇这主要讲解http的缓存处理,大体流程如下: 1.什么是缓存 2.为什么要用缓存 3.HTTP缓存机制 4.CacheControl类详解 5.CacheStrategy 类详解 CacheStrategy 缓存策略类 OKHTTP使用了CacheStrategy实现了上面的流程图,它根据之前缓存的结果与当前将要发送Request的header进行策略,并得出是否进行请求的结果 类的构造 CacheStrategy使用Factory模式进行构造,通过Factory的get()方法获取CacheStrategy的对象,参数如下: public Factory(long nowMillis get() { CacheStrategy candidate = getCandidate(); if (candidate.networkRequest ! 客户端和服务器根据一定的机制(策略CacheStrategy ),在需要的时候使用缓存的数据作为网络响应,节省了时间和宽带。

    1.2K50发布于 2018-08-30
  • 来自专栏胡飞洋的Android进阶

    网络请求框架OkHttp3全解系列 - (三)拦截器详解1:重试重定向、桥、缓存(重点)

    CacheStrategy strategy = new CacheStrategy.Factory(now, chain.request(), cacheCandidate).get(); Request CacheStrategy是如何获取的,这里先不看。 ,这里我们就去看看它是如何生成的,看起来就是一行代码: CacheStrategy strategy = new CacheStrategy.Factory(now, chain.request get() { CacheStrategy candidate = getCandidate(); if (candidate.networkRequest ! 接着回头看get()方法: public CacheStrategy get() { CacheStrategy candidate = getCandidate();

    3.5K10发布于 2020-07-23
  • 来自专栏每天学点Android知识

    深入理解OkHttp源码(四)——缓存

    cacheStrategy) { Cache.this.trackResponse(cacheStrategy); } }; 从代码中可以看出,InternalCache接口中的每个方法的实现都交给了外部类 CacheStrategy对象对一个请求和一个缓存响应作分析,指出应该使用网络响应还是缓存响应,又或者两者都要。 CacheStrategycacheStrategy) { requestCount++; if (cacheStrategy.networkRequest ! networkCount++; } else if (cacheStrategy.cacheResponse !

    1.2K20发布于 2019-08-14
  • 来自专栏深入理解Android

    开源框架源码解析系列(1)——进入OkHttp的世界

    CacheStrategy strategy = new CacheStrategy.Factory(now, chain.request(), cacheCandidate).get(); 3.5.3 CacheStrategy#Factory方法 其实就是从缓存的cacheResponse中取出一些值进行赋值 3.5.4 CacheStrategy.Factory#get方法 public CacheStrategy get() { CacheStrategy candidate = getCandidate(); if (candidate.networkRequest return new CacheStrategy(null, null); } return candidate; } 主要逻辑在getCandidate方法中 CacheStrategy return new CacheStrategy(null, null); } 如果外部设置了onlyIfCached(只读缓存),但缓存又无效,那就构造的CacheStrategy中既没有

    81720编辑于 2022-06-22
  • 来自专栏哈利迪ei

    Android |《看完不忘系列》之okhttp

    cache.get(chain.request()) : null; //创建缓存策略 CacheStrategy strategy = new CacheStrategy.Factory CacheStrategy即缓存策略,CacheInterceptor拦截器会根据他拿到网络请求networkRequest、缓存响应cacheResponse,从而决定是使用网络还是缓存。 //CacheStrategy.java //内部类工厂,生产CacheStrategy static class Factory { //一些字段:servedDate、lastModified get() { CacheStrategy candidate = getCandidate(); if (candidate.networkRequest ! return new CacheStrategy(xxx); } } getCandidate里面就是根据header字段得到各种策略,然后交给拦截器处理,感兴趣的读者自行阅读啦。

    1.1K20发布于 2020-08-10
  • 来自专栏哈利迪ei

    Android | okhttp细枝篇

    Cache-Control > Expires > etag > lastModified,从树干篇中可知,在CacheInterceptor拦截器中会从磁盘取出缓存的Response(如果有),然后在CacheStrategy.Factory 中,解析缓存的Response来得到缓存策略CacheStrategy, //CacheStrategy.Factory.java CacheStrategy getCandidate() { maxStaleMillis) { Response.Builder builder = cacheResponse.newBuilder(); return new CacheStrategy request.newBuilder() .headers(conditionalRequestHeaders.build()) .build(); return new CacheStrategy (conditionalRequest, cacheResponse); } 强缓存内部细节, //CacheStrategy.Factory.java //强缓存 long computeFreshnessLifetime

    1.1K30发布于 2020-08-17
  • 来自专栏用户7621540的专栏

    你所不知道的堆外缓存

    部分类的封装方式如下: public class OhcCacheStrategy implements CacheStrategy { /** * 日志 */ private ,模仿了redis的键被动驱逐方式,实现如下: public class OffheapCacheWorker { /** * 带参注入 * * @param cacheStrategy */ public OffheapCacheWorker(CacheStrategy cacheStrategy) { this.cacheStrategy = cacheStrategy */ private OffheapCacheHelper offheapCacheHelper; /** * 缓存构建器 */ private CacheStrategy cacheStrategy; /** * 过期key检测线程 */ private Thread expireCheckThread; /**

    87920编辑于 2022-12-17
  • 来自专栏花落的技术专栏

    OkHttp源码流程分析

    = null && request.cacheControl.onlyIfCached) { return CacheStrategy(null, null) } return candidate } private fun computeCandidate(): CacheStrategy { // No cached response //这里的cacheResponse是缓存中命中的 所以如果为null 表示之前没有缓存 if (cacheResponse == null) { return CacheStrategy //如果缺少tls握手 直接请求网络 if (request.isHttps && cacheResponse.handshake == null) { return CacheStrategy isCacheable(cacheResponse, request)) { return CacheStrategy(request, null) } //

    60150发布于 2021-11-24
  • 来自专栏Jack的Android之旅

    刨解OkHttp之缓存机制

    cache.get(chain.request()) : null; long now = System.currentTimeMillis(); //获取缓存策略 CacheStrategy strategy = new CacheStrategy.Factory(now, chain.request(), cacheCandidate).get(); //缓存策略请求 = null) { //缓存到本地 if (HttpHeaders.hasBody(response) && CacheStrategy.isCacheable(response 来获取缓存策略,CacheStrategy根据之前缓存的结果与当前将要发送Request的header进行策略,并得出是否进行请求的结果。 image.png 因为我把注释流程都写在代码了,大家可以看上面方法代码理解,其整体缓存流程如下: 如果有缓存,则取出缓存否则为null 根据CacheStrategy拿到它的缓存策略请求和响应 缓存策略请求和缓存策略响应为空

    1.2K20发布于 2018-08-28
  • 来自专栏非著名程序员

    玩转 WebView ,突破系统限制,让缓存更简单,更灵活

    setCacheStrategy(WebViewCache.CacheStrategy.FORCE), 这样对于静态资源直接走缓存,不需要和服务器沟通走 304 缓存,这样会更快;如果静态资源要更新, web 前端同学修改静态资源链接,如给链接加 md5 值,或者加版本等等方式; CacheWebView webview; webview.setCacheStrategy(WebViewCache.CacheStrategy.FORCE

    2.8K60发布于 2018-02-09
  • 来自专栏Java与Android技术栈

    ReentrantReadWriteLock读写锁及其在 RxCache 中的使用

    <T> Record<T> get(String key, Type type, CacheStrategy cacheStrategy) { try { readLock.lock T> record = null; if (Preconditions.isNotBlanks(key, type)) { switch (cacheStrategy

    77020发布于 2019-01-28
  • 来自专栏码上积木

    从通信流程聊OkHttp拦截器

    get(chain.request()) //缓存策略类 val strategy = CacheStrategy.Factory(now, chain.request(), = null) { if (response.promisesBody() && CacheStrategy.isCacheable(response, networkRequest)) { 3、缓存策略(CacheStrategy)到底是怎么处理网络和缓存的?networkRequest什么时候为空? 首先,看看缓存哪里取的: val cacheCandidate = cache?. 最后再看看缓存策略方法 CacheStrategy.Factory().compute() class CacheStrategy internal constructor( val networkRequest == null) { return CacheStrategy(request, null) } //...

    87710发布于 2021-03-24
  • 来自专栏liulun

    winform实现下拉控件的无限级联动(DevExpress版)

    / 加载行业类型(仅父类)         ///          public void InitTrade()         {             trades = CacheStrategy.Instance.GetObject param name="e"></param>         public void InitTrade(string trade_code)         {             trades = CacheStrategy.Instance.GetObject

    92820编辑于 2022-05-09
  • 来自专栏码上积木

    OkHttp三问—百度真题

    例子有CacheInterceptor拦截器中又个CacheStrategy对象: CacheStrategy strategy = new CacheStrategy.Factory(now,

    67310发布于 2020-10-29
  • 来自专栏Android知识点总结

    P1-Android基于MVP实现号码归属地查询

    1981462002@qq.com * 说明:网络封装,连接网络获取数据,并写缓存 */ public abstract class GetDataWithCache { private CacheStrategy private Map<String, String> mParam; public GetDataWithCache(String url, Map<String, String> param, CacheStrategy cacheStrategy) { mCacheStrategy = cacheStrategy; mUrl = url; mParam = param

    82020发布于 2018-09-29
  • 可扩展系统设计的黄金法则与Go语言实践|得物技术

    // cache/cache.go:缓存策略接口package cache// CacheStrategy 定义缓存操作的接口type CacheStrategy interface { Get( ttl.Seconds()), }).Err()}// cache_context.go:缓存上下文(管理策略切换)type CacheContext struct { strategy CacheStrategy // 当前使用的缓存策略}func NewCacheContext(strategy CacheStrategy) *CacheContext { return &CacheContext{strategy : strategy}}// SwitchStrategy 动态切换缓存策略func (c *CacheContext) SwitchStrategy(strategy CacheStrategy) { 优势:当需要新增缓存类型(如本地内存缓存)时,只需实现CacheStrategy接口,无需修改现有代码;切换缓存策略时,只需调用SwitchStrategy方法,客户端无感知。

    41510编辑于 2025-08-28
  • 来自专栏Windows Community

    UWP 创建动画的极简方式 — LottieUWP

    建议在 LottieAnimationView.setAnimation(String, CacheStrategy) 使用 CacheStrategy,这样可以避免每次反复的加载动画。

    1.9K70发布于 2018-04-28
  • 来自专栏Wooola的技术博客

    OKHttp原理解析

    cache.get(chain.request()) : null; CacheStrategy strategy = new CacheStrategy.Factory(now, chain.request CacheStrategy 缓存策略,根据上面的Http机制、request,确定是使用网络的response、还是缓存的response cache.get(chain.request()) 从 DiskLruCache

    1.1K11发布于 2021-05-27
领券