* Fixed iterator bug in rsmemcache.h

* Added rsmemcache.h to libretroshare.pro
 * initialised variables in p3idservice (was killing caching).



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5766 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-11-03 13:15:21 +00:00
parent a074c40e6f
commit ffa8299718
4 changed files with 23 additions and 15 deletions

View File

@ -429,7 +429,8 @@ HEADERS += retroshare/rsgame.h \
util/rswin.h \
util/rsrandom.h \
util/radix64.h \
util/pugiconfig.h
util/pugiconfig.h \
util/rsmemcache.h
SOURCES += dbase/cachestrapper.cc \
dbase/fimonitor.cc \

View File

@ -55,9 +55,13 @@ p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *ne
mIdMtx("p3IdService")
{
mCacheTest_LastTs = 0;
mCacheLoad_LastCycle = 0;
mCacheTest_Active = false;
mCacheLoad_LastCycle = 0;
mCacheLoad_Status = 0;
mCacheDataCount = 0;
}
void p3IdService::service_tick()

View File

@ -34,6 +34,8 @@
#include <map>
#include <string>
#include "util/rsmemcache.h"
/*
* Identity Service
*

View File

@ -22,11 +22,13 @@
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef RS_MEM_CACHE
#define RS_MEM_CACHE
#ifndef RS_UTIL_MEM_CACHE
#define RS_UTIL_MEM_CACHE
#include <map>
#include <time.h>
#include <iostream>
#include <inttypes.h>
/************************************************************************************/
/************************************************************************************/
@ -46,7 +48,7 @@
template<class Key, class Value> class RsMemCache
{
RsMemCache(uint32_t max_size = DEFAULT_MEM_CACHE_SIZE)
:mMaxSize(max_size) { return; }
:mMaxSize(max_size), mDataCount(0) { return; }
bool is_cached(const Key &key) const;
bool fetch(const Key &key, Value &data);
@ -80,7 +82,7 @@ template<class Key, class Value> class RsMemCache
template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Key &key) const
{
std::map<Key,cache_data>::const_iterator it;
typename std::map<Key,cache_data>::const_iterator it;
it = mDataMap.find(key);
if (it == mDataMap.end())
{
@ -98,8 +100,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Ke
template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &key, Value &data)
{
std::map<Key, cache_data>::const_iterator it;
//std::map<Key, cache_data<Key, Value> >::iterator it;
typename std::map<Key, cache_data>::const_iterator it;
it = mDataMap.find(key);
if (it == mDataMap.end())
{
@ -130,7 +131,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::store(const Key &k
std::cerr << std::endl;
// For consistency
std::map<Key, cache_data>::const_iterator it;
typename std::map<Key, cache_data>::const_iterator it;
it = mDataMap.find(key);
if (it != mDataMap.end())
{
@ -166,9 +167,9 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::update_lrumap(cons
}
/* find old entry */
std::multimap<time_t, Key>::iterator mit;
std::multimap<time_t, Key>::iterator sit = mLruMap.lower_bound(old_ts);
std::multimap<time_t, Key>::iterator eit = mLruMap.upper_bound(old_ts);
typename std::multimap<time_t, Key>::iterator mit;
typename std::multimap<time_t, Key>::iterator sit = mLruMap.lower_bound(old_ts);
typename std::multimap<time_t, Key>::iterator eit = mLruMap.upper_bound(old_ts);
for(mit = sit; mit != eit; mit++)
{
@ -230,7 +231,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
{
while(count_to_clear > 0)
{
std::multimap<time_t, Key>::iterator mit = mLruMap.begin();
typename std::multimap<time_t, Key>::iterator mit = mLruMap.begin();
if (mit != mLruMap.end())
{
Key key = mit->second;
@ -238,7 +239,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
/* now clear from real cache */
//std::map<Key, cache_data<Key, Value> >::iterator it;
std::map<Key, cache_data>::iterator it;
typename std::map<Key, cache_data>::iterator it;
it = mDataMap.find(key);
if (it == mDataMap.end())
{
@ -270,4 +271,4 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
#endif // RS_MEM_CACHE
#endif // RS_UTIL_MEM_CACHE