From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001
From: 单军华
Date: Wed, 11 Jul 2018 10:47:42 +0800
Subject: [PATCH] 首次上传
---
screendisplay/Pods/YYCache/YYCache/YYCache.m | 139 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 139 insertions(+), 0 deletions(-)
diff --git a/screendisplay/Pods/YYCache/YYCache/YYCache.m b/screendisplay/Pods/YYCache/YYCache/YYCache.m
new file mode 100644
index 0000000..e6cdcba
--- /dev/null
+++ b/screendisplay/Pods/YYCache/YYCache/YYCache.m
@@ -0,0 +1,139 @@
+//
+// YYCache.m
+// YYCache <https://github.com/ibireme/YYCache>
+//
+// Created by ibireme on 15/2/13.
+// Copyright (c) 2015 ibireme.
+//
+// This source code is licensed under the MIT-style license found in the
+// LICENSE file in the root directory of this source tree.
+//
+
+#import "YYCache.h"
+#import "YYMemoryCache.h"
+#import "YYDiskCache.h"
+
+@implementation YYCache
+
+- (instancetype) init {
+ NSLog(@"Use \"initWithName\" or \"initWithPath\" to create YYCache instance.");
+ return [self initWithPath:@""];
+}
+
+- (instancetype)initWithName:(NSString *)name {
+ if (name.length == 0) return nil;
+ NSString *cacheFolder = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
+ NSString *path = [cacheFolder stringByAppendingPathComponent:name];
+ return [self initWithPath:path];
+}
+
+- (instancetype)initWithPath:(NSString *)path {
+ if (path.length == 0) return nil;
+ YYDiskCache *diskCache = [[YYDiskCache alloc] initWithPath:path];
+ if (!diskCache) return nil;
+ NSString *name = [path lastPathComponent];
+ YYMemoryCache *memoryCache = [YYMemoryCache new];
+ memoryCache.name = name;
+
+ self = [super init];
+ _name = name;
+ _diskCache = diskCache;
+ _memoryCache = memoryCache;
+ return self;
+}
+
++ (instancetype)cacheWithName:(NSString *)name {
+ return [[self alloc] initWithName:name];
+}
+
++ (instancetype)cacheWithPath:(NSString *)path {
+ return [[self alloc] initWithPath:path];
+}
+
+- (BOOL)containsObjectForKey:(NSString *)key {
+ return [_memoryCache containsObjectForKey:key] || [_diskCache containsObjectForKey:key];
+}
+
+- (void)containsObjectForKey:(NSString *)key withBlock:(void (^)(NSString *key, BOOL contains))block {
+ if (!block) return;
+
+ if ([_memoryCache containsObjectForKey:key]) {
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ block(key, YES);
+ });
+ } else {
+ [_diskCache containsObjectForKey:key withBlock:block];
+ }
+}
+
+- (id<NSCoding>)objectForKey:(NSString *)key {
+ id<NSCoding> object = [_memoryCache objectForKey:key];
+ if (!object) {
+ object = [_diskCache objectForKey:key];
+ if (object) {
+ [_memoryCache setObject:object forKey:key];
+ }
+ }
+ return object;
+}
+
+- (void)objectForKey:(NSString *)key withBlock:(void (^)(NSString *key, id<NSCoding> object))block {
+ if (!block) return;
+ id<NSCoding> object = [_memoryCache objectForKey:key];
+ if (object) {
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ block(key, object);
+ });
+ } else {
+ [_diskCache objectForKey:key withBlock:^(NSString *key, id<NSCoding> object) {
+ if (object && ![_memoryCache objectForKey:key]) {
+ [_memoryCache setObject:object forKey:key];
+ }
+ block(key, object);
+ }];
+ }
+}
+
+- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key {
+ [_memoryCache setObject:object forKey:key];
+ [_diskCache setObject:object forKey:key];
+}
+
+- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key withBlock:(void (^)(void))block {
+ [_memoryCache setObject:object forKey:key];
+ [_diskCache setObject:object forKey:key withBlock:block];
+}
+
+- (void)removeObjectForKey:(NSString *)key {
+ [_memoryCache removeObjectForKey:key];
+ [_diskCache removeObjectForKey:key];
+}
+
+- (void)removeObjectForKey:(NSString *)key withBlock:(void (^)(NSString *key))block {
+ [_memoryCache removeObjectForKey:key];
+ [_diskCache removeObjectForKey:key withBlock:block];
+}
+
+- (void)removeAllObjects {
+ [_memoryCache removeAllObjects];
+ [_diskCache removeAllObjects];
+}
+
+- (void)removeAllObjectsWithBlock:(void(^)(void))block {
+ [_memoryCache removeAllObjects];
+ [_diskCache removeAllObjectsWithBlock:block];
+}
+
+- (void)removeAllObjectsWithProgressBlock:(void(^)(int removedCount, int totalCount))progress
+ endBlock:(void(^)(BOOL error))end {
+ [_memoryCache removeAllObjects];
+ [_diskCache removeAllObjectsWithProgressBlock:progress endBlock:end];
+
+}
+
+- (NSString *)description {
+ if (_name) return [NSString stringWithFormat:@"<%@: %p> (%@)", self.class, self, _name];
+ else return [NSString stringWithFormat:@"<%@: %p>", self.class, self];
+}
+
+@end
--
Gitblit v1.8.0