简体   繁体   English

如何从PFUser缓存PFFile

[英]How to cache PFFile from PFUser

So, I have several user on my pfuser and each user have profile picture. 因此,我的pfuser上有多个用户,每个用户都有个人资料图片。 And everytime user enter my app feed page, my app download the user profile picture. 每当用户进入我的应用程序供稿页面时,我的应用程序都会下载用户个人资料图片。

I have no problem caching query but I have problem to cache direct pfuser file, like below code: 我在缓存查询时没有问题,但是在缓存直接pfuser文件时遇到了问题,例如以下代码:

let userPicture: AnyObject? = PFUser.currentUser()?["profilePicture"] as? PFFile

userPicture?.cachePolicy = PFCachePolicy.CacheThenNetwork

I got below warning: 我得到以下警告:

Could not find an overload for 'cachePolicy' that accepts the supplied arguments 找不到接受提供的参数的'cachePolicy'的重载

How can I cache pffile? 如何缓存pffile? do I have to store the image in NSUserDeafaults? 我必须将映像存储在NSUserDeafaults中吗?

PFFile doesn't have a property called cachePolicy. PFFile没有名为cachePolicy的属性。

The thing is you don't have to worry about cache for PFFile because Parse will do it for you by checking the file uuid/url. 事情是您不必担心PFFile的缓存,因为Parse会通过检查文件uuid / url为您完成缓存。 Once a PFFile has been downloaded, it will be cached and getData will fetch from cache and it will not use up an API request. 一旦下载了PFFile,它将被缓存,并且getData将从缓存中获取,并且不会用完API请求。

Storing images in NSUsersDefaults is a very bad idea and should be discouraged. 在NSUsersDefaults中存储图像是一个非常糟糕的主意,因此不建议使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM