FatFractal customer forums



Author Topic: Example of FFLocalStorage  (Read 2619 times)

kwylez

  • Newbie
  • *
  • Posts: 27
    • View Profile
Example of FFLocalStorage
« on: March 27, 2014, 09:52:59 PM »
Can you provide an example of using FFLocalStore with one my objects? The scenario is I need to persist my Profile object.


jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Example of FFLocalStorage
« Reply #1 on: March 27, 2014, 11:07:41 PM »
Code: [Select]

 FFLocalStorageSQLite * localStorage = [[FFLocalStorageSQLite alloc] initWithDatabaseKey:@"unique key"];
   
    //[localStorage setDebug:YES];
   
    [localStorage wipeAllData];
   
    FatFractal * ff = [[FatFractal alloc] initWithBaseUrl:@"https://<domain>.fatfractal.com/<application>"];
   
    FFReadRequest * request = [[FatFractal main] newReadRequest];
   
    NSString * uri = [NSString stringWithFormat:@"/Profile/<guid>"];
   
    [request prepareGetFromUri:uri];
   
    [request executeAsyncWithOptions:FFReadOptionCacheResponse | FFReadOptionUseCachedIfCached andBlock:^(FFReadResponse *response) {
       
       Profile * profile = response.obj
       
    }];


Before you create your ff instance, create the local storage. Note upon logout the local storage is wiped.

Use a read request to store any sort of request, including blobs to the local storage using FFReadOptionCacheResponse.

Using FFReadOptionUseCachedIfCached will first look into the cache to see of the object at the uri is there, if not it faults to the online database.

I do have sample code at my disposable thanks to @GaryCasey for lazily loading and caching blobs on objects, I can post if you like.

Hope this helps

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Example of FFLocalStorage
« Reply #2 on: March 28, 2014, 08:46:21 AM »
Thanks @jonnycools ... one correction to the above ... logout does NOT wipe out local storage ... but the entries in local storage are tied to a particular logged-in user.

One of our customers has rather complicated user management requirements; as a result she has N+1 FatFractal instances, N for each different user logged in, for acccess to data which is secured for them, plus one more for data which is shared by all

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Example of FFLocalStorage
« Reply #3 on: March 28, 2014, 08:50:59 AM »
See also https://forum.fatfractal.com/forum/index.php?topic=44.msg236#msg236

I am so far behind in documenting this feature, I must make time and do a blog post soon
« Last Edit: April 08, 2014, 05:35:59 PM by gkc »

kwylez

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Example of FFLocalStorage
« Reply #4 on: April 08, 2014, 10:49:41 AM »
Thank you guys! Sorry for the late response. This helps a ton.

ssdscott

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Example of FFLocalStorage
« Reply #5 on: April 22, 2014, 12:48:24 AM »
@gkc - what does "FatFractal instance" refer to in your 3/28 post?  is itů an application?  a collection?  (still new to the lingo)
thanks!

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Example of FFLocalStorage
« Reply #6 on: April 22, 2014, 07:23:57 PM »
Means, an instance of the iOS FatFractal class
« Last Edit: April 23, 2014, 05:43:14 AM by gkc »

 

Copyright © FatFractal customer forums