00001 #ifndef WHOISCACHEIMPL_H
00002 #define WHOISCACHEIMPL_H
00003 #include <abuse/WhoisCache.h>
00004 #include <abuse/CriticalSection.h>
00005 #include <map>
00006 #include "MsXml.h"
00007
00008 class File;
00009 class InternalCacheEntry;
00010
00011 class Cache: public WhoisCache
00012 {
00013 public:
00014 Cache(const std::string& filename)throw(std::runtime_error);
00015 virtual ~Cache();
00016 virtual CacheResult get(const Url& url)const;
00017 virtual void addRir(const UrlRange& nr, const std::string& rir)throw(std::runtime_error);
00018 virtual void add(const ZeWhois::WhoisList& lst)throw(std::runtime_error);
00019 virtual void remove(const UrlRange& range);
00020
00021 virtual const CacheMap& getTree()const;
00022 #ifdef _DEBUG
00023
00024 void dumpCache();
00025 #endif
00026
00027 void save()throw(std::runtime_error);
00028 private:
00029
00030 void initTree()throw(std::runtime_error);
00031
00032 void checkVersion(const DocumentPtr&)throw(std::runtime_error);
00033
00034
00035 void recursiveBuild(const NodeListPtr& elements,CacheMap& _map)const throw(std::runtime_error);
00036
00037 static UrlRange getRange(const ElementPtr& el) throw(std::runtime_error);
00038
00039
00040 CacheEntry* createEntry(const ElementPtr& el)const throw(std::runtime_error);
00041
00042 void recursiveFind(const Url& url,const CacheMap& _map,CacheResult& cr)const throw(std::runtime_error);
00043
00044 static CacheMap::const_iterator fastfind(const UrlRange& range,const CacheMap& _map);
00045
00046 static CacheMap::iterator fastfind(const UrlRange& range,CacheMap& _map);
00047
00048 static CacheMap::const_iterator fastfind(const Url& url,const CacheMap& _map);
00049
00050 static void recursiveSave(ElementPtr& pEl, const CacheMap& _map)throw(std::runtime_error);
00051
00052 static void recursiveAdd(const UrlRange& range,const InternalCacheEntry* pEntry,CacheMap& _map)throw(std::runtime_error);
00053
00054 static void recursiveDelete(const UrlRange& range,CacheMap& _map);
00055
00056 void writeLock();
00057
00058 CacheMap m_head;
00059
00060 std::string m_filename;
00061
00062 std::string m_path;
00063
00064 mutable CriticalSection m_mutex;
00065
00066
00067 mutable int m_nReads;
00068
00069 bool m_bDirty;
00070 };
00071
00072 #endif