[英]Any way to cache the current user object in memory without going through the login/signup calls and localStorage?
In Parse, a user object is created and cached in memory after login or signup successfull calls, and can be retrieved using current. 在Parse中,将在登录或注册成功调用之后创建一个用户对象并将其缓存在内存中,并可以使用current进行检索。
My need now is to create and cache the user object in memory without going through the login/signup calls and also without having to store the object in the local storage. 现在,我需要在内存中创建和缓存用户对象,而无需进行登录/注册调用,也不必将对象存储在本地存储中。 I mean something like assigning a new user object in memory so that
Parse.User.current
will return it. 我的意思是类似在内存中分配一个新的用户对象,以便
Parse.User.current
将其返回。 Again I shouldn't go through login and signup. 再次,我不应该通过登录和注册。
If I go through login call: 如果我通过登录电话:
Parse.User.logIn(login, password, {
success: function(user) {
// At this moment the user object is cached
},
error: function(error) {
}
});
But in my case, I don't go through the login, but instead I have the user id, and with it I can get the user object: 但就我而言,我没有经过登录,而是拥有了用户标识,有了它,我可以获得用户对象:
var query = new Parse.Query(Parse.User);
query.equalTo('objectId',result.id);
query.first({
success: function(user){
// Now I want to cache the user in memory so that Parse.User.current will return it to me whenever I want
// I tried to cache this in localStorage but whenever I retrieve it, I get null object
},
error: function(error){
alert(error);
}
});
It is not entirely clear what you want, but you could simply call toJSON()
on the current user and save that JSON in your cache, either local storage or whatever you are using. 尚不清楚您想要什么,但是您可以简单地在当前用户上调用
toJSON()
并将该JSON保存在本地存储或正在使用的任何内容的缓存中。
Is there more you want? 您还想要更多吗? If so please expand your question.
如果是这样,请扩大您的问题。
Parse users are logged in until they log out, parse caches the user for you. 解析用户将登录,直到他们注销为止,解析将为您缓存用户。
You can access that cached user by doing this in your code: 您可以通过在代码中执行以下操作来访问该缓存的用户:
var query = new Parse.Query(Parse.User.Current());
see docs: 查看文档:
https://parse.com/questions/is-it-possible-to-keep-a-user-logged-in-after-signing-up-logging-in-via-the-rest-api https://parse.com/questions/is-it-possible-to-keep-a-user-logged-in-after-signing-up-logging-in-via-the-rest-api
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.