简体   繁体   English

有什么方法可以在不通过登录/注册调用和localStorage的情况下将当前用户对象缓存在内存中?

[英]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.

相关问题 是否可以通过AJSAX调用Gmail API,而无需通过JS库? - Any way to make AJAX calls to Gmail API without going through JS library? 登录详细信息不在localStorage中 - Login details not going in localStorage 递归地进行排列而不存储在 memory - Recursively going through permutations without storing in memory 是否有任何方法可以检测用户是否从本地存储中删除了任何项目 - Is there is any way to detect if the user removed any item from localstorage 有什么方法可以让 Javascript 对象知道它何时超出范围? - Is there any way for a Javascript object to know when it is going out of scope? 有没有办法在 Vuejs 中“观察”本地存储? - Is there any way to 'watch' for localstorage in Vuejs? 有没有办法随机循环对象的键? - Is there any way to loop randomly through the keys of an object? 在没有任何后端调用或数据库的情况下验证AngularJS中的用户 - Validate the user in AngularJS without any back end calls or Databases 如何在JQuery中使用localStorage为Ajax调用创建自定义缓存机制? - How to create custom cache mechanism for ajax calls using localStorage in JQuery? 使用没有 JSON 的 localStorage 存储对象 - storing an object with localStorage without JSON
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM