OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BESCache.h
Go to the documentation of this file.
1
// BESCache.h
2
3
// This file is part of bes, A C++ back-end server implementation framework
4
// for the OPeNDAP Data Access Protocol.
5
6
// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7
// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8
//
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
13
//
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
//
23
// You can contact University Corporation for Atmospheric Research at
24
// 3080 Center Green Drive, Boulder, CO 80301
25
26
// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27
// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28
//
29
// Authors:
30
// pwest Patrick West <pwest@ucar.edu>
31
// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33
#ifndef BESCache_h_
34
#define BESCache_h_ 1
35
36
#include <algorithm>
37
#include <map>
38
#include <string>
39
#include <sstream>
40
41
#include "
BESObj.h
"
42
43
class
BESKeys
;
44
45
static
const
unsigned
int
MAX_LOCK_RETRY_MS = 5000;
// in microseconds
46
static
const
unsigned
int
MAX_LOCK_TRIES = 16;
47
58
class
BESCache
:
public
BESObj
59
{
60
public
:
61
63
struct
cache_entry
64
{
65
string
name
;
66
unsigned
long
long
size
;
67
};
68
71
typedef
std::multimap<double, cache_entry, std::greater<double> >
CacheFilesByAgeMap
;
72
74
struct
CacheDirInfo
75
{
76
CacheDirInfo
()
77
:
_total_cache_files_size
(0ULL)
78
,
_num_files_in_cache
(0ULL)
79
,
_contents
()
80
{}
81
82
~CacheDirInfo
()
83
{
84
clear
();
85
}
86
87
void
clear
()
88
{
89
_total_cache_files_size
= 0ULL;
90
_num_files_in_cache
= 0ULL;
91
_contents
.clear();
92
}
93
94
unsigned
long
long
get_avg_size
()
const
95
{
96
return
( (
_num_files_in_cache
> 0) ?
97
(
_total_cache_files_size
/
_num_files_in_cache
) :
98
(0ULL) );
99
}
100
101
std::string
toString
()
const
102
{
103
std::ostringstream oss;
104
oss <<
"Numfiles: "
<<
_num_files_in_cache
<<
""
105
" Total size: "
<<
_total_cache_files_size
;
106
return
oss.str();
107
}
108
109
unsigned
long
long
_total_cache_files_size
;
110
unsigned
long
long
_num_files_in_cache
;
111
BESCache::CacheFilesByAgeMap
_contents
;
112
};
// struct CacheDirInfo
113
114
115
private
:
116
// slashes are replaced with this char to make cache file.
117
static
const
char
BES_CACHE_CHAR =
'#'
;
118
119
string
_cache_dir ;
120
string
_prefix ;
121
unsigned
long
long
_cache_size_in_megs ;
122
int
_lock_fd ;
123
124
void
check_ctor_params();
125
BESCache
() {}
126
public
:
127
BESCache
(
const
string
&
cache_dir
,
128
const
string
&
prefix
,
129
unsigned
long
long
sizeInMegs ) ;
130
BESCache
(
BESKeys
&keys,
131
const
string
&cache_dir_key,
132
const
string
&prefix_key,
133
const
string
&size_key ) ;
134
virtual
~BESCache
() {}
135
136
virtual
bool
lock
(
unsigned
int
retry_ms,
137
unsigned
int
num_tries ) ;
138
virtual
bool
unlock
() ;
139
140
virtual
bool
is_cached
(
const
string
&src,
string
&target ) ;
141
virtual
void
purge
( ) ;
142
143
string
cache_dir
( )
const
{
return
_cache_dir ; }
144
string
match_prefix
()
const
{
return
_prefix + BES_CACHE_CHAR; };
145
string
prefix
( )
const
{
return
_prefix ; }
146
unsigned
long
long
cache_size
( )
const
{
return
_cache_size_in_megs ; }
147
148
void
collect_cache_dir_info
(
149
BESCache::CacheDirInfo
& cd_info
//output
150
)
const
;
151
152
virtual
void
dump
( ostream &strm )
const
;
153
};
154
155
#endif // BESCache_h_
156
dispatch
BESCache.h
Generated by
1.8.3.1