separated out the cache access part from beaglequeueindexer. this avoids having to link the pure query programs with indexing code
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include "beaglequeuecache.h"
|
||||
#include "circache.h"
|
||||
#include "debuglog.h"
|
||||
#include "rclconfig.h"
|
||||
#include "pathut.h"
|
||||
#include "rcldoc.h"
|
||||
|
||||
BeagleQueueCache::BeagleQueueCache(RclConfig *cnf)
|
||||
{
|
||||
string ccdir;
|
||||
cnf->getConfParam("webcachedir", ccdir);
|
||||
if (ccdir.empty())
|
||||
ccdir = "webcache";
|
||||
ccdir = path_tildexpand(ccdir);
|
||||
// If not an absolute path, compute relative to config dir
|
||||
if (ccdir.at(0) != '/')
|
||||
ccdir = path_cat(cnf->getConfDir(), ccdir);
|
||||
|
||||
int maxmbs = 40;
|
||||
cnf->getConfParam("webcachemaxmbs", &maxmbs);
|
||||
m_cache = new CirCache(ccdir);
|
||||
m_cache->create(off_t(maxmbs)*1000*1024, CirCache::CC_CRUNIQUE);
|
||||
}
|
||||
|
||||
BeagleQueueCache::~BeagleQueueCache()
|
||||
{
|
||||
delete m_cache;
|
||||
}
|
||||
|
||||
// Read document from cache. Return the metadata as an Rcl::Doc
|
||||
// @param htt Beagle Hit Type
|
||||
bool BeagleQueueCache::getFromCache(const string& udi, Rcl::Doc &dotdoc,
|
||||
string& data, string *htt)
|
||||
{
|
||||
string dict;
|
||||
|
||||
if (!m_cache->get(udi, dict, data))
|
||||
return false;
|
||||
|
||||
ConfSimple cf(dict, 1);
|
||||
|
||||
if (htt)
|
||||
cf.get(Rcl::Doc::keybght, *htt, "");
|
||||
|
||||
// Build a doc from saved metadata
|
||||
cf.get("url", dotdoc.url, "");
|
||||
cf.get("mimetype", dotdoc.mimetype, "");
|
||||
cf.get("fmtime", dotdoc.fmtime, "");
|
||||
cf.get("fbytes", dotdoc.fbytes, "");
|
||||
dotdoc.sig = "";
|
||||
list<string> names = cf.getNames("");
|
||||
for (list<string>::const_iterator it = names.begin();
|
||||
it != names.end(); it++) {
|
||||
cf.get(*it, dotdoc.meta[*it], "");
|
||||
}
|
||||
dotdoc.meta[Rcl::Doc::keyudi] = udi;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef _beaglequeuecache_h_included_
|
||||
#define _beaglequeuecache_h_included_
|
||||
/* @(#$Id: $ (C) 2009 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
class RclConfig;
|
||||
namespace Rcl {
|
||||
class Db;
|
||||
class Doc;
|
||||
}
|
||||
class CirCache;
|
||||
|
||||
/**
|
||||
* Manage the CirCache for the Beagle Queue indexer. Separated from the main
|
||||
* indexer code because it's also used for querying (getting the data for a
|
||||
* preview
|
||||
*/
|
||||
class BeagleQueueCache {
|
||||
public:
|
||||
BeagleQueueCache(RclConfig *config);
|
||||
~BeagleQueueCache();
|
||||
|
||||
bool getFromCache(const string& udi, Rcl::Doc &doc, string& data,
|
||||
string *hittype = 0);
|
||||
// We could write proxies for all the circache ops, but why bother?
|
||||
CirCache *cc() {return m_cache;}
|
||||
|
||||
private:
|
||||
CirCache *m_cache;
|
||||
};
|
||||
|
||||
#endif /* _beaglequeuecache_h_included_ */
|
||||
Reference in New Issue
Block a user