Cache Queries Using the Parse Javascript SDK

Can I cache requests using the Parse (parse.com) Javascript SDK?

The only link I found is https://parse.com/questions/javascript-sdk-caching , and it says that it is not currently supported.

Since the last answer to the last link was linked 4 months ago, I would like to know if it is currently supported or if there are ways to work around these requests.

+4
source share
1 answer

with a little work, you can cache it (or something else) yourself using the wrapper method.

, https://parse.com/docs/js/symbols/Parse.Query.html :

var cacheKeys = [],
    cacheVals = [];

function q(cls, ok, fail) { // query wrapper that implements caching

    // store or fetch from cache if available:
    var slot = cacheKeys.indexOf(cls);
    if (slot !== -1) {
        return ok(cacheVals[slot]);
    } else {
        slot=cacheKeys.length;
        cacheKeys.push(cls);
    }
    //normal query code:
    var query = new Parse.Query(cls);

    query.find({
        success: function(results) {
            cacheVals[slot] = results; //cache results 
            ok(results); // call traditionally 
        },

        error: fail || console.error.bind(console)
    });

} // end  q()

, , WeakMap ( ), . , , q() . JSON.stringify(cls) , . , , - JSON ...

+5

Source: https://habr.com/ru/post/1526669/


All Articles