Skip to content
프로젝트

소개

네트워크 리소스를 위한 스마트 스토리지

시스템 및 인프라

이 수치를 측정하는 방법

What you can do

  • Load cached object from memory by URL
  • Load cached object from file by URL
  • Load object from network by URL
  • Store loaded object to file

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

APSmartStorage helps to get data from network and automatically caches data on disk or in memory in a smart configurable way. Here is how the APSmartStorage flow diagram looks like: Build Status

Features

  • Load cached object from memory by URL
  • Load cached object from file by URL
  • Load object from network by URL
  • Store loaded object to file
  • Store loaded object to memory
  • Parse loaded data from network (for instance, NSData to UIImage)
  • Track loading progress
  • Automatically purge memory cache on memory warning
  • Set max object count to keep in memory to prevent memory overflow
  • Set custom NSURLSessionConfiguration

Installation

Add APSmartStorage pod to Podfile

Using

Load object

Here is example how to use APSmartStorage to store images

// setup data parsing block
APSmartStorage.sharedInstance.parsingBlock = ^(NSData *data, NSURL *url)
{
    return [UIImage imageWithData:data scale:UIScreen.mainScreen.scale];
};
...
// show some progress/activity
...
// load object with URL
[APSmartStorage.sharedInstance loadObjectWithURL:imageURL completion:^(id object, NSError *error)
{
    // hide progress/activity
    if (error)
    {
        // show error
    }
    else
    {
        // do something with object
    }
}];

Very often you don't need to store downloaded object in memory. For instance, you perform some background download for future, and you don't want to keep this objects in memory right now.

[APSmartStorage.sharedInstance loadObjectWithURL:someURL storeInMemory:NO completion:^(id object, NSError *error)
{
    // do something
}];

But if any method call sets storeInMemory:YES object will be stored in memory

Track load progress
[APSmartStorage.sharedInstance loadObjectWithURL:someURL storeInMemory:NO progress:^(NSUInteger percents)
{
    // show progress percents value is between 0 and 100
}                                     completion:^(id object, NSError *error)
{
    // do something
}];
Update stored object

Objects stored at files could become outdated after some time, and application should reload it from network

[APSmartStorage.sharedInstance reloadObjectWithURL:objectURL completion:(id object, NSError *error)
{
    if (error)
    {
        // show error and do something like use outdated version of object
    }
    else
    {
        // do something with object
    }
}];
Remove objects from memory
// remove object from memory
[APSmartStorage.sharedInstance removeObjectWithURLFromMemory:objectURL];
// remove all objects form memory
[APSmartStorage.sharedInstance removeAllFromMemory];
Remove object from memory and delete file storage
// remove object from memory and remove it file
[APSmartStorage.sharedInstance removeObjectWithURLFromStorage:objectURL];
// remove all objects from memory and all storage files
[APSmartStorage.sharedInstance removeAllFromStorage];

This methods also cancel network requests. And if request has been cancelled, callbacks will run with nil as object and with error with code 701.

Parse network and file data

If parsingBlock doesn't set you will receive raw NSData downloaded from network or read from file. So you should set one in most cases. If you need to parse data of different formats it will be a bit more complicated:

APSmartStorage.sharedInstance.parsingBlock = ^(NSData *data, NSURL *url)
{
    // is URL of image
    if ([url isImageURL])
    {
        return [UIImage imageWithData:data scale:UIScreen.mainScreen.scale];
    }
    // this is URL of something else
    else
    {
        return [SomeObject objectWithData:data];
    }
};
Set max objects count to keep in memory

If max object count reached random object will be removed from memory before add next one

APSmartStorage.sharedInstance.maxObjectCount = 10;
Setup custom NSURLSessionConfiguration
APSmartStorage.sharedInstance.sessionConfiguration = sessionConfiguration;

History

Releases

======================= githalytics.com alpha If you have improvements or concerns, feel free to post an issue and write details.

Check out all Alterplay's GitHub projects. Email us with other ideas and projects.

관련 프로젝트 살펴보기

불러오는 중…