Marble

CacheStoragePolicy.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2007 Tobias Koenig <[email protected]>
4 //
5 
6 
7 // Own
8 #include "CacheStoragePolicy.h"
9 
10 // Qt
11 #include <QDir>
12 
13 using namespace Marble;
14 
15 CacheStoragePolicy::CacheStoragePolicy( const QString &cacheDirectory )
16  : m_cache( cacheDirectory )
17 {
18  if ( ! QDir( cacheDirectory ).exists() )
19  QDir::root().mkpath( cacheDirectory );
20 }
21 
22 CacheStoragePolicy::~CacheStoragePolicy()
23 {
24 }
25 
26 bool CacheStoragePolicy::fileExists( const QString &fileName ) const
27 {
28  return m_cache.exists( fileName );
29 }
30 
31 bool CacheStoragePolicy::updateFile( const QString &fileName, const QByteArray &data )
32 {
33  if ( !m_cache.insert( fileName, data ) ) {
34  m_errorMsg = QObject::tr("Unable to insert data into cache");
35  return false;
36  }
37 
38  return true;
39 }
40 
41 void CacheStoragePolicy::clearCache()
42 {
43  m_cache.clear();
44 }
45 
46 QString CacheStoragePolicy::lastErrorMessage() const
47 {
48  return m_errorMsg;
49 }
50 
51 QByteArray CacheStoragePolicy::data( const QString &fileName )
52 {
53  QByteArray data;
54  m_cache.find( fileName, data );
55 
56  return data;
57 }
58 
59 void CacheStoragePolicy::setCacheLimit( quint64 bytes )
60 {
61  m_cache.setCacheLimit( bytes );
62 }
63 
64 quint64 CacheStoragePolicy::cacheLimit() const
65 {
66  return m_cache.cacheLimit();
67 }
68 
69 #include "moc_CacheStoragePolicy.cpp"
QDir root()
bool mkpath(const QString &dirPath) const const
Binds a QML item to a specific geodetic location in screen coordinates.
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:50:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.