openModeller  Version 1.5.0
CacheManager Class Reference

#include <CacheManager.hh>

Collaboration diagram for CacheManager:
Collaboration graph

Public Member Functions

 ~CacheManager ()
 

Static Public Member Functions

static void initialize (const std::string dir="")
 
static bool isCached (const std::string id, const std::string subdir="")
 
static bool isCachedMd5 (const std::string id, const std::string subdir="")
 
static void cache (const std::string id, const std::ostringstream &content, const std::string subdir="")
 
static void cacheMd5 (const std::string id, const std::ostringstream &content, const std::string subdir="")
 
static std::string getContentLocation (const std::string id, const std::string subdir="")
 
static std::string getContentLocationMd5 (const std::string id, const std::string subdir="")
 
static std::string getContentIdMd5 (const std::string id)
 
static int eraseCache (const std::string id, const std::string subdir="")
 
static int eraseCacheMd5 (const std::string id, const std::string subdir="")
 

Private Member Functions

 CacheManager ()
 

Static Private Member Functions

static CacheManager_getInstance ()
 
static void _ensureInitialized ()
 

Private Attributes

std::string _cacheDir
 

Detailed Description

Declaration of CacheManager class.

Author
Renato De Giovanni (renato (at) cria . org . br)
Id:
CacheManager.hh 5947 2014-03-27 19:05:39Z rdg

LICENSE INFORMATION

Copyright(c) 2012 by CRIA - Centro de Referencia em Informacao Ambiental

http://www.cria.org.br

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details:

http://www.gnu.org/copyleft/gpl.html This class was initially created to help handling openModeller WCS rasters. It is used by env_io/WcsProxyRaster, which receives an openModeller WCS raster identifier in the form wcs>wcs_service_url>coverage_id and uses the cache manager to convert the identifier into a safe MD5 hash string that can be used as a file name to store the WCS XML content expected by GDAL. In the future it may be used for other things, such as caching background points or caching entire rasters. TODO: write flush method (so far the cache directories tend to keep growing).

Definition at line 48 of file CacheManager.hh.

Constructor & Destructor Documentation

CacheManager::~CacheManager ( )

Definition at line 61 of file CacheManager.cpp.

CacheManager::CacheManager ( )
private

Definition at line 53 of file CacheManager.cpp.

Member Function Documentation

void CacheManager::_ensureInitialized ( )
staticprivate

Definition at line 131 of file CacheManager.cpp.

References _cacheDir, _getInstance(), and initialize().

Referenced by cache(), getContentLocation(), and isCached().

Here is the call graph for this function:

CacheManager & CacheManager::_getInstance ( )
staticprivate

Definition at line 68 of file CacheManager.cpp.

Referenced by _ensureInitialized(), cache(), getContentLocation(), initialize(), and isCached().

void CacheManager::cache ( const std::string  id,
const std::ostringstream &  content,
const std::string  subdir = "" 
)
static

Cache the specified content identified by id.

Parameters
idContent identifier.
contentContent.
subdirSubdirectory inside cache dir. Optional.

Definition at line 184 of file CacheManager.cpp.

References _cacheDir, _ensureInitialized(), _getInstance(), createPath(), Log::error(), and Log::instance().

Referenced by cacheMd5().

Here is the call graph for this function:

void CacheManager::cacheMd5 ( const std::string  id,
const std::ostringstream &  content,
const std::string  subdir = "" 
)
static

Cache the specified content identified by id. Id is converted to an MD5 hash.

Parameters
idContent identifier.
contentContent.
subdirSubdirectory inside cache dir. Optional.

Definition at line 219 of file CacheManager.cpp.

References cache(), and getContentIdMd5().

Here is the call graph for this function:

int CacheManager::eraseCache ( const std::string  id,
const std::string  subdir = "" 
)
static

Erases cached content identified by the specified id.

Parameters
idContent identifier.
subdirSubdirectory inside cache dir. Optional.
Returns
0 if it worked, non zero if it failed (errno).

Definition at line 285 of file CacheManager.cpp.

References getContentLocation().

Referenced by eraseCacheMd5().

Here is the call graph for this function:

int CacheManager::eraseCacheMd5 ( const std::string  id,
const std::string  subdir = "" 
)
static

Erases cached content identified by the specified id. Id is converted to an MD5 hash.

Parameters
idContent identifier.
subdirSubdirectory inside cache dir. Optional.
Returns
0 if it worked, non zero if it failed (errno).

Definition at line 295 of file CacheManager.cpp.

References eraseCache(), and getContentIdMd5().

Here is the call graph for this function:

std::string CacheManager::getContentIdMd5 ( const std::string  id)
static

Return the local id of cached content. Id is converted to an MD5 hash.

Parameters
idContent identifier.
Returns
Local id of cached content.

Definition at line 258 of file CacheManager.cpp.

References MD5_Final(), MD5_Init(), and MD5_Update().

Referenced by cacheMd5(), eraseCacheMd5(), getContentLocationMd5(), and isCachedMd5().

Here is the call graph for this function:

std::string CacheManager::getContentLocation ( const std::string  id,
const std::string  subdir = "" 
)
static

Return the location of cached content.

Parameters
idContent identifier.
subdirSubdirectory inside cache dir. Optional.
Returns
Location of cached content (file path).

Definition at line 227 of file CacheManager.cpp.

References _cacheDir, _ensureInitialized(), and _getInstance().

Referenced by eraseCache(), and getContentLocationMd5().

Here is the call graph for this function:

std::string CacheManager::getContentLocationMd5 ( const std::string  id,
const std::string  subdir = "" 
)
static

Return the location of cached content. Id is converted to an MD5 hash.

Parameters
idContent identifier.
subdirSubdirectory inside cache dir. Optional.
Returns
Location of cached content (file path).

Definition at line 250 of file CacheManager.cpp.

References getContentIdMd5(), and getContentLocation().

Here is the call graph for this function:

void CacheManager::initialize ( const std::string  dir = "")
static

Set the cache directory. When not specified, try the OM_CACHE_PATH environment variable. If undefined, use current_dir/cache.

Parameters
dirCache directory

Definition at line 77 of file CacheManager.cpp.

References _cacheDir, _getInstance(), Settings::count(), createPath(), Log::debug(), Settings::get(), getWorkingPath(), Log::instance(), and pathExists().

Referenced by _ensureInitialized().

Here is the call graph for this function:

bool CacheManager::isCached ( const std::string  id,
const std::string  subdir = "" 
)
static

Indicates if the specified content identified by id is cached.

Parameters
idContent identifier.
subdirSubdirectory inside cache dir. Optional.
Returns
Yes or no

Definition at line 144 of file CacheManager.cpp.

References _cacheDir, _ensureInitialized(), _getInstance(), and createPath().

Referenced by isCachedMd5().

Here is the call graph for this function:

bool CacheManager::isCachedMd5 ( const std::string  id,
const std::string  subdir = "" 
)
static

Indicates if the specified content identified by id is cached. Id is converted to an MD5 hash.

Parameters
idContent identifier.
subdirSubdirectory inside cache dir. Optional.
Returns
Yes or no

Definition at line 176 of file CacheManager.cpp.

References getContentIdMd5(), and isCached().

Here is the call graph for this function:

Member Data Documentation

std::string CacheManager::_cacheDir
private

Definition at line 135 of file CacheManager.hh.

Referenced by _ensureInitialized(), cache(), getContentLocation(), initialize(), and isCached().


The documentation for this class was generated from the following files: