//
//  CoreData.m
//  Project
//
//  Created by Vae on 2018/11/2.
//

#import "CacheData.h"
#import "WebService.h"
#import <PINCache/PINCache.h>

@interface CacheData ()
@property(nonatomic, strong) NSString *routerUrlOrHtmlString;
@property(nonatomic, strong) PINDiskCache *htmlStringCache;
@end

@implementation CacheData

-(PINDiskCache *)htmlStringCache{
	if (!_htmlStringCache) {
		_htmlStringCache  = [[PINDiskCache alloc] initWithName:NSStringFromSelector(@selector(htmlStringCache))];
		_htmlStringCache.ageLimit = 24 * 3600;
		_htmlStringCache.ttlCache = YES;
	}
	return _htmlStringCache;
}

-(id)getpageContentWithKey:(NSString *)key{
	GetPageContentResponse *response = (GetPageContentResponse *) [self.htmlStringCache objectForKey:key];
	return response;
}

-(void)setpageContent:(GetPageContentResponse *)response key:(NSString *)key{
	if (response) {
		[self.htmlStringCache setObject:(id)response forKey:key];
	}else{
		[self.htmlStringCache removeObjectForKey:key];
	}
}

- (void)removeAllCache {
	[self.htmlStringCache removeAllObjects];
}
@end
