Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CACHE_H__
00020 #define __CACHE_H__
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025
00026 #include <string>
00027 #include <map>
00028 #include <iostream>
00029 #include <boost/shared_ptr.hpp>
00030
00031 #include "statistics.h"
00032 #include "diskstream.h"
00033 #include "getclocktime.hpp"
00034 #include "dsodefs.h"
00035
00038 namespace gnash {
00039
00040
00041 static const size_t CACHE_LIMIT = 102400000;
00042
00043
00044
00045
00047
00048 class DSOEXPORT Cache {
00049 public:
00050 Cache();
00051 ~Cache();
00052 DSOEXPORT static Cache& getDefaultInstance();
00053
00054 void DSOEXPORT addPath(const std::string &name, const std::string &fullpath);
00055 std::string &findPath(const std::string &name);
00056 void removePath(const std::string &name);
00057
00058 void addResponse(const std::string &name, const std::string &response);
00059 std::string &findResponse(const std::string &name);
00060 void removeResponse(const std::string &name);
00061
00062 void addFile(const std::string &name, boost::shared_ptr<DiskStream > &file);
00063 boost::shared_ptr<DiskStream> & findFile(const std::string &name);
00064 void removeFile(const std::string &name);
00065
00068 void dump() const { dump(std::cerr); }
00070 void dump(std::ostream& os) const;
00071
00072 #ifdef USE_STATS_CACHE
00073 std::string DSOEXPORT stats(bool xml) const;
00074 #endif
00075 private:
00078 std::map<std::string, std::string> _pathnames;
00081 std::map<std::string, std::string> _responses;
00084 std::map<std::string, boost::shared_ptr<DiskStream> > _files;
00085
00088 size_t _max_size;
00089
00091 #ifdef USE_STATS_CACHE
00092 struct timespec _last_access;
00093 long _pathname_lookups;
00094 long _pathname_hits;
00095 long _response_lookups;
00096 long _response_hits;
00097 long _file_lookups;
00098 long _file_hits;
00099 #endif
00100
00101
00102 size_t _pagesize;
00103
00104 cygnal::AMF::filetype_e _filetype;
00105 };
00106
00108 inline std::ostream& operator << (std::ostream& os, const Cache& cache)
00109 {
00110 cache.dump(os);
00111 return os;
00112 }
00113
00114 }
00115
00116 #endif // __CACHE_H__
00117
00118
00119
00120
00121