Newer
Older
CasicBioRecNew / dao / util / CacheManager.cpp
#include "CacheManager.h"

CacheManager::CacheManager()
{
    deptCache = new QList<QVariantMap>();
}

QList<QVariantMap> * CacheManager::getDeptCachePtr()
{
    return deptCache;
}

void CacheManager::updateDeptCache()
{
    SysDeptDao deptDao;
    QVector<QVariantMap> deptList = deptDao.findRecordsByProperty("pid", "0");

    // 将之前的缓存清空
    if (deptCache->isEmpty() == false)
    {
        QMutex mutex;
        mutex.lock();
        deptCache->clear();
        mutex.unlock();
    }

    // 如果查询到数据则更新缓存
    if (deptList.isEmpty() == false)
    {
        for (int i = 0; i < deptList.size(); i++)
        {
            deptDao.appendChild(deptCache, deptList.at(i));
        }
    }
}