GithubHelp home page GithubHelp logo

acnetworking's Introduction

ACNetworking

简介

本框架是基于AFNetworking的网络缓存库,可将网络请求的返回结果缓存到内存及磁盘,且支持自定义生成缓存Key。

核心类

  • ACNetworkingManager 框架的主入口,封装了基于AFNetworking的各种post和get方法。

  • ACNetCache 请求结果缓存工具类,支持结果的写入、读取、删除。可以指定缓存目录及命名空间。

  • ACNetCacheKeyGenerator 一个Block定义,负责生成结果缓存的Key。

引入

Pod

pod 'ACNetworking', '~> 1.0.1'

手动

下载工程文件,将ACNetworking文件夹copy到项目中即可

使用

1.创建ACNetworkingManager:

该类的构造方法需要传入一个AFHttpSessionManager,一个ACNetCache,一个ACNetCacheKeyGenerator,均有默认参数

ACNetworkingManager  *your_manager = [ACNetworkingManager manager];
ACNetworkingManager  *your_manager = [ACNetworkingManager managerWithSessionManager:your_session_manager];
ACNetCache  *your_cache = [ACNetCache cacheWithNamespace:@"your_cache_name_space" directiory:@"your_cache_directory" keyGenerator:your_keyGenerator];
ACNetworkingManager  *your_manager = [ACNetworkingManager managerWithSessionManager:your_session_manager 
responseCache:your_cache];

2.请求API,以POST请求为例:

  • 只取网络请求
[your_manager postRequest:@"your_api" parameters: your_parameter completion: your_completion];
  • 优先取缓存,没有缓存取本地:
可以传入过期时长:
[your_manager postData:@"your_api" expires:your_expire_time parameters:your_parameter completion:your_completion];
如果不需要过期时长:
[your_manager postData:@"your_api" parameters:your_parameter completion:your_completion];
  • 只取本地缓存:
[your_manager postLocal:@"your_api" parameters: your_parameter completion: your_completion];
  • 先取本地,然后再取网络:
[your_manager postLocalAndNet:@"your_api" parameters: your_parameter completion: your_completion];
  • 以上方法的完整版本:
[your_manager post:@"your_api" expires:your_expire_time options:your_option1 |  your_option2 parameters:your_parameter progress:your_progress completion:your_completion];

2.以上API均有对应的GET版本

acnetworking's People

Contributors

iallenc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.