예제 #1
0
QString FLDiskCache::absoluteFilePath(const QString &key)
{
  QString fileCache(AQ_DISKCACHE_DIRPATH + '/' + key);
  if (!QFile::exists(fileCache))
    return QString::null;
  return fileCache;
}
예제 #2
0
bool FLDiskCache::find(const QString &key, QString &str)
{
  QString fileCache(AQ_DISKCACHE_DIRPATH + '/' + key);
  QFile fi(fileCache);
  if (!fi.open(IO_ReadOnly))
    return false;
  QTextStream t(&fi);
  str = t.read();
  fi.close();
  return true;
}
예제 #3
0
bool FLDiskCache::find(const QString &key, QByteArray &ba)
{
  QString fileCache(AQ_DISKCACHE_DIRPATH + '/' + key +
                    QString::fromLatin1("-BIN"));
  QFile fi(fileCache);
  if (!fi.open(IO_ReadOnly))
    return false;
  QDataStream dat(&fi);
  dat >> ba;
  fi.close();
  return true;
}
예제 #4
0
bool FLDiskCache::insert(const QString &key, const QString &str)
{
  QString fileCache(AQ_DISKCACHE_DIRPATH + '/' + key);
  QFile fi(fileCache);
  QDir d(AQ_DISKCACHE_DIRPATH);
  if (!d.exists())
    d.mkdir(AQ_DISKCACHE_DIRPATH);
  else if (fi.exists())
    return true;
  if (!str.isEmpty()) {
    if (fi.open(IO_WriteOnly)) {
      QTextStream t(&fi);
      t << str;
      fi.close();
      return true;
    }
  }
  return false;
}
예제 #5
0
bool FLDiskCache::insert(const QString &key, const QByteArray &ba)
{
  QString fileCache(AQ_DISKCACHE_DIRPATH + '/' + key +
                    QString::fromLatin1("-BIN"));
  QFile fi(fileCache);
  QDir d(AQ_DISKCACHE_DIRPATH);
  if (!d.exists())
    d.mkdir(AQ_DISKCACHE_DIRPATH);
  else if (fi.exists())
    return true;
  if (!ba.isEmpty()) {
    if (fi.open(IO_WriteOnly)) {
      QDataStream dat(&fi);
      dat << ba;
      fi.close();
      return true;
    }
  }
  return false;
}
예제 #6
0
void testFileCache() {
    cout << "FileCache => ";
    long sampleSize = 1024;
    long errors = 0;
    char c[9];
    strcpy(c,"data.txt");
    FileCache <TestStructure> fileCache((char*)&c, (long)(sampleSize), true);
    char a[5];
    strcpy(a,"test");
    int intmax = 32765;
    // set object to OUT
    long t1 = clock();
    for(long i=0; i<sampleSize; i++) {
        TestStructure* ts = new TestStructure();
        ts->dataValue = i+2;
        int OUT = fileCache.add(ts);
    }
    long t2 = clock()-t1;

    // test object from Get
    t1 = clock();

    for(long int i=0; i<sampleSize; i++) {
        TestStructure* ffs = fileCache.get(i);
        if(ffs == 0x0 || ffs->dataValue != i+2) {
            errors++;
        }
    }
    t2 = clock()-t1;

    if(errors == 0) {
        cout << "Pass" << endl;
    } else {
        cout << "FAIL errors:" << errors << endl;
    }
    //fileCache.clean();
}