YDN-DB getting Store: null not exist

YDN-DB getting Store: null not exist

本文关键字:not exist null getting Store YDN-DB      更新时间:2023-09-26

我可以在将记录添加到存储后验证记录的存在,但是当我在另一个函数中声明一个新变量指向相同的数据库和存储并执行查询时,我得到以下错误消息。

Store: null not exists.

我用来检索数据的方法被复制到我添加记录的位置,只是为了确保它的语法是正确的,它在那里工作。但是当我在另一个函数中,它不再找到数据。

下面是一些代码:

我的目标是跟踪何时缓存数据,以便在数据过期时重新获取数据。"updateCacheAge"方法似乎有效。记录对象用我期望的JSON对象填充。

updateCacheAge = function (dbName, cacheName) {
    // updates the mashCacheAge.  This helps track how old/stale a cache is.
    var cacheJSON = {
        id: cacheName,
        updatedDate: new Date().getTime()
    };
    mashDB = new ydn.db.Storage(dbName);
    mashDB.put({ name: 'mashCacheAge', keyPath: 'id' }, cacheJSON).done(function (key) {
        mashDB.executeSql('SELECT * FROM mashCacheAge WHERE id = ''' + cacheName + '''').then(function (record) {
            $log.log('mashCacheAge record for: ' + cacheName);
            $log.log(record);
        });
    });

    $log.log(cacheName + ': mashCache was re-created.');
}

这是isStale函数。第一次执行时,我预计这可能会失败,因为缓存中没有任何内容。当这种情况发生时,我知道获取我的数据,然后更新cacheAge,以防止我回到数据库,直到缓存过期。

我确信我的代码可以改进,但这是我解决问题的第一次尝试。我遇到的问题是我刚刚保存到mashCacheAge存储的数据不存在,错误消息似乎表明存储本身不存在。

我是不是做了什么傻事?

isStale = function (dbName, cacheName, minutes) {
    // db: is 'mashCache'
    // store: No store is provided but might be added later to remove constaint 'mashCacheAge'
    // subject: is the name of the cache being evaluated.
    // minutes: is the number of minutes before the cache is considered stale.
    var deferred = $q.defer();
    var result = true;
    // get milliseconds version of minutes.
    var ageToleranceMilliseconds = (minutes * 60) * 1000;
    var currentDateMilliseconds = new Date().getTime();
    isStaleMashDB = new ydn.db.Storage(dbName);
    try {
        isStaleMashDB.executeSql('SELECT * FROM mashCacheAge WHERE id = ''' + cacheName + '''').then(function (record) {
            $log.log('mashCacheAge record for: ' + cacheName);
            $log.log(record);

            var durationMilliseconds = currentDateMilliseconds - record[0].updatedDate;
            // Check if the data is stale.
            if (durationMilliseconds > ageToleranceMilliseconds) {
                result = true;
            }
            else { result = false; }
            deferred.resolve(result);
        });
    }
    catch (e) { deferred.resolve(true); }
    return deferred.promise;
};

我找到了敌人,敌人就是我。

我对这个库的最初实验是有效的,我在我的模块的根中留下了那个实验的残余。我知道得更清楚,但我忘记了,浪费了我几个小时的工作时间。我的坏。

我正在为我的YDN数据库重用"db"名称,这些冲突。不过JavaScript并没有向我抱怨。当我注释掉所有最初的实验后,一切都开始像预期的那样工作了。