fix: cache added synchronized

This commit is contained in:
yangqingren
2020-07-31 18:44:16 +08:00
parent fa0059d8bf
commit 523071052b
3 changed files with 17 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "SVGAPlayer"
s.version = "2.5.4"
s.version = "2.5.5"
s.summary = "SVGAPlayer 是一个高性能的动画播放器"
s.description = <<-DESC
SVGA 是一种全新的动画格式,由 YY UED 团队主导开发;

View File

@@ -50,6 +50,7 @@ static SVGAParser *parser;
@"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true",
];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// parser.enabledMemoryCache = YES;
[parser parseWithURL:[NSURL URLWithString:items[arc4random() % items.count]]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
@@ -66,6 +67,7 @@ static SVGAParser *parser;
NSParagraphStyleAttributeName: para,
}];
[self.aPlayer setAttributedText:str forKey:@"banner"];
// self.aPlayer.mianRunLoopMode = NSDefaultRunLoopMode;
[self.aPlayer startAnimation];
}

View File

@@ -209,19 +209,27 @@ static NSMapTable * weakCache;
}
+ (SVGAVideoEntity *)readCache:(NSString *)cacheKey {
SVGAVideoEntity * object = [videoCache objectForKey:cacheKey];
if (!object) {
object = [weakCache objectForKey:cacheKey];
@synchronized (videoCache) {
SVGAVideoEntity * object = [videoCache objectForKey:cacheKey];
if (!object) {
@synchronized (weakCache) {
object = [weakCache objectForKey:cacheKey];
}
}
return object;
}
return object;
}
- (void)saveCache:(NSString *)cacheKey {
[videoCache setObject:self forKey:cacheKey];
@synchronized (videoCache) {
[videoCache setObject:self forKey:cacheKey];
}
}
- (void)saveWeakCache:(NSString *)cacheKey {
[weakCache setObject:self forKey:cacheKey];
@synchronized (weakCache) {
[weakCache setObject:self forKey:cacheKey];
}
}
@end