OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ossim::S3HeaderCache Class Reference

#include <S3HeaderCache.h>

Public Types

typedef std::shared_ptr< S3HeaderCacheNodeNode_t
 
typedef std::string Key_t
 
typedef ossim_int64 TimeIndex_t
 
typedef std::map< Key_t, Node_tCacheType
 
typedef std::map< TimeIndex_t, Key_tCacheTimeIndexType
 

Public Member Functions

 S3HeaderCache ()
 
virtual ~S3HeaderCache ()
 
bool getCachedFilesize (const Key_t &key, ossim_int64 &filesize) const
 
void addHeader (const Key_t &key, Node_t &node)
 
void setMaxCacheEntries (ossim_int64 maxEntries)
 

Static Public Member Functions

static std::shared_ptr< S3HeaderCacheinstance ()
 

Protected Member Functions

void shrinkEntries ()
 

Protected Attributes

std::mutex m_mutex
 
CacheType m_cache
 
CacheTimeIndexType m_cacheTime
 
ossim_int64 m_maxCacheEntries
 

Static Protected Attributes

static std::shared_ptr< S3HeaderCachem_instance
 

Detailed Description

Definition at line 27 of file S3HeaderCache.h.

Member Typedef Documentation

◆ CacheTimeIndexType

Definition at line 34 of file S3HeaderCache.h.

◆ CacheType

Definition at line 33 of file S3HeaderCache.h.

◆ Key_t

typedef std::string ossim::S3HeaderCache::Key_t

Definition at line 31 of file S3HeaderCache.h.

◆ Node_t

Definition at line 30 of file S3HeaderCache.h.

◆ TimeIndex_t

Definition at line 32 of file S3HeaderCache.h.

Constructor & Destructor Documentation

◆ S3HeaderCache()

ossim::S3HeaderCache::S3HeaderCache ( )

Definition at line 7 of file S3HeaderCache.cpp.

◆ ~S3HeaderCache()

ossim::S3HeaderCache::~S3HeaderCache ( )
virtual

Definition at line 13 of file S3HeaderCache.cpp.

14 {
15  m_cache.clear();
16 }

Member Function Documentation

◆ addHeader()

void ossim::S3HeaderCache::addHeader ( const Key_t key,
Node_t node 
)

Definition at line 44 of file S3HeaderCache.cpp.

45 {
46  std::unique_lock<std::mutex> lock(m_mutex);
47  if(m_maxCacheEntries<=0) return;
48  CacheType::const_iterator iter = m_cache.find(key);
49 
50  if(iter != m_cache.end())
51  {
52  iter->second->m_filesize = node->m_filesize;
53  }
54  else
55  {
57  {
58  shrinkEntries();
59  }
60  m_cache.insert( std::make_pair(key, node) );
61  m_cacheTime.insert( std::make_pair(node->m_timestamp, key) );
62  }
63 }
ossim_int64 m_maxCacheEntries
Definition: S3HeaderCache.h:51
CacheTimeIndexType m_cacheTime
Definition: S3HeaderCache.h:50
long long ossim_int64

◆ getCachedFilesize()

bool ossim::S3HeaderCache::getCachedFilesize ( const Key_t key,
ossim_int64 filesize 
) const

Definition at line 28 of file S3HeaderCache.cpp.

29 {
30  std::unique_lock<std::mutex> lock(m_mutex);
31  bool result = false;
32  if(m_maxCacheEntries<=0) return result;
33  CacheType::const_iterator iter = m_cache.find(key);
34 
35  if(iter != m_cache.end())
36  {
37  filesize = iter->second->m_filesize;
38  result = true;
39  }
40 
41  return result;
42 }
ossim_int64 m_maxCacheEntries
Definition: S3HeaderCache.h:51

◆ instance()

std::shared_ptr< ossim::S3HeaderCache > ossim::S3HeaderCache::instance ( )
static

Definition at line 18 of file S3HeaderCache.cpp.

19 {
20  if(!m_instance)
21  {
22  m_instance = std::make_shared<S3HeaderCache>();
23  }
24 
25  return m_instance;
26 }
static std::shared_ptr< S3HeaderCache > m_instance
Definition: S3HeaderCache.h:46

◆ setMaxCacheEntries()

void ossim::S3HeaderCache::setMaxCacheEntries ( ossim_int64  maxEntries)

◆ shrinkEntries()

void ossim::S3HeaderCache::shrinkEntries ( )
protected

Definition at line 65 of file S3HeaderCache.cpp.

66 {
67  ossim_int64 targetSize = static_cast<ossim_int64>(0.2*m_maxCacheEntries);
68 
69  if(m_cacheTime.empty()) return;
70  if(targetSize >= (ossim_int64)m_cache.size())
71  {
72  m_cache.clear();
73  m_cacheTime.clear();
74  return;
75  }
76 
77  CacheTimeIndexType::iterator iter = m_cacheTime.begin();
78 
79  while(targetSize > 0)
80  {
81  m_cache.erase(iter->second);
82  iter = m_cacheTime.erase(iter);
83  --targetSize;
84  }
85 }
ossim_int64 m_maxCacheEntries
Definition: S3HeaderCache.h:51
CacheTimeIndexType m_cacheTime
Definition: S3HeaderCache.h:50
long long ossim_int64

Member Data Documentation

◆ m_cache

CacheType ossim::S3HeaderCache::m_cache
protected

Definition at line 49 of file S3HeaderCache.h.

◆ m_cacheTime

CacheTimeIndexType ossim::S3HeaderCache::m_cacheTime
protected

Definition at line 50 of file S3HeaderCache.h.

◆ m_instance

std::shared_ptr< ossim::S3HeaderCache > ossim::S3HeaderCache::m_instance
staticprotected

Definition at line 46 of file S3HeaderCache.h.

◆ m_maxCacheEntries

ossim_int64 ossim::S3HeaderCache::m_maxCacheEntries
protected

Definition at line 51 of file S3HeaderCache.h.

◆ m_mutex

std::mutex ossim::S3HeaderCache::m_mutex
mutableprotected

Definition at line 47 of file S3HeaderCache.h.


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