From fb4eeb1cea21adee05c9755fd039000c40e9d636 Mon Sep 17 00:00:00 2001 From: Brian Hoffman Date: Sat, 17 Jun 2017 14:00:06 -0400 Subject: [PATCH 1/2] Global key value cache --- app/Jasonette/JasonGlobalAction.h | 10 ++++++ app/Jasonette/JasonGlobalAction.m | 54 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app/Jasonette/JasonGlobalAction.h create mode 100644 app/Jasonette/JasonGlobalAction.m diff --git a/app/Jasonette/JasonGlobalAction.h b/app/Jasonette/JasonGlobalAction.h new file mode 100644 index 00000000..6c683acb --- /dev/null +++ b/app/Jasonette/JasonGlobalAction.h @@ -0,0 +1,10 @@ +// +// Cache.h +// Jasonette +// +// Copyright © 2016 gliechtenstein. All rights reserved. +// +#import "JasonAction.h" +#import "JasonHelper.h" +@interface JasonGlobalAction : JasonAction +@end diff --git a/app/Jasonette/JasonGlobalAction.m b/app/Jasonette/JasonGlobalAction.m new file mode 100644 index 00000000..d1fe001f --- /dev/null +++ b/app/Jasonette/JasonGlobalAction.m @@ -0,0 +1,54 @@ +// +// Cache.m +// Jasonette +// +// Copyright © 2016 gliechtenstein. All rights reserved. +// +#import "JasonGlobalAction.h" + +@implementation JasonGlobalAction +- (void)reset{ + + NSString *normalized_url = @"global"; + NSMutableDictionary *set = [[NSMutableDictionary alloc] init]; + [[NSUserDefaults standardUserDefaults] setObject:set forKey:normalized_url]; + [[NSUserDefaults standardUserDefaults] synchronize]; + self.VC.current_cache = set; + [[Jason client] success: set]; + +} +/* + + (NSDictionary *)get:(NSString *)url{ + NSString *normalized_url = [url lowercaseString]; + return [[NSUserDefaults standardUserDefaults] objectForKey:normalized_url]; + } + */ +- (void)set{ + if([[self.options description] containsString:@"{{"] && [[self.options description] containsString:@"}}"]){ + [[Jason client] error]; + return; + } + + @try { + NSString *normalized_url = @"global"; + NSDictionary *to_set = [[NSUserDefaults standardUserDefaults] objectForKey:normalized_url]; + NSMutableDictionary *mutated; + if(to_set && to_set.count > 0){ + mutated = [to_set mutableCopy]; + for(NSString *key in self.options){ + mutated[key] = self.options[key]; + } + } else { + mutated = [self.options mutableCopy]; + } + [[NSUserDefaults standardUserDefaults] setObject:mutated forKey:normalized_url]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + self.VC.current_cache = mutated; + [[Jason client] success: mutated]; + } @catch (NSException *e){ + [[Jason client] error]; + } + +} +@end From 9ba174338023a254c1e4e6bc6941e15fc6c94c17 Mon Sep 17 00:00:00 2001 From: Brian Hoffman Date: Sat, 17 Jun 2017 14:03:46 -0400 Subject: [PATCH 2/2] Fix headers --- app/Jasonette/JasonGlobalAction.h | 2 +- app/Jasonette/JasonGlobalAction.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Jasonette/JasonGlobalAction.h b/app/Jasonette/JasonGlobalAction.h index 6c683acb..f4d0cb62 100644 --- a/app/Jasonette/JasonGlobalAction.h +++ b/app/Jasonette/JasonGlobalAction.h @@ -1,5 +1,5 @@ // -// Cache.h +// JasonGlobalAction.h // Jasonette // // Copyright © 2016 gliechtenstein. All rights reserved. diff --git a/app/Jasonette/JasonGlobalAction.m b/app/Jasonette/JasonGlobalAction.m index d1fe001f..a627ece2 100644 --- a/app/Jasonette/JasonGlobalAction.m +++ b/app/Jasonette/JasonGlobalAction.m @@ -1,5 +1,5 @@ // -// Cache.m +// JasonGlobalAction.m // Jasonette // // Copyright © 2016 gliechtenstein. All rights reserved.