Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global space key-value storage cache #214

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/Jasonette/JasonGlobalAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// JasonGlobalAction.h
// Jasonette
//
// Copyright © 2016 gliechtenstein. All rights reserved.
//
#import "JasonAction.h"
#import "JasonHelper.h"
@interface JasonGlobalAction : JasonAction
@end
54 changes: 54 additions & 0 deletions app/Jasonette/JasonGlobalAction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// JasonGlobalAction.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