MemoryStorageService(const DOMElement* e);
virtual ~MemoryStorageService();
- void createString(const char* context, const char* key, const char* value, time_t expiration);
+ bool createString(const char* context, const char* key, const char* value, time_t expiration);
int readString(const char* context, const char* key, string* pvalue=NULL, time_t* pexpiration=NULL, int version=0);
int updateString(const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0);
bool deleteString(const char* context, const char* key);
- void createText(const char* context, const char* key, const char* value, time_t expiration) {
+ bool createText(const char* context, const char* key, const char* value, time_t expiration) {
return createString(context, key, value, expiration);
}
int readText(const char* context, const char* key, string* pvalue=NULL, time_t* pexpiration=NULL, int version=0) {
return count;
}
-void MemoryStorageService::createString(const char* context, const char* key, const char* value, time_t expiration)
+bool MemoryStorageService::createString(const char* context, const char* key, const char* value, time_t expiration)
{
Context& ctx = writeContext(context);
SharedLock locker(m_lock, false);
if (i!=ctx.m_dataMap.end()) {
// Not yet expired?
if (time(NULL) < i->second.expiration)
- throw IOException("attempted to insert a record with duplicate key ($1)", params(1,key));
+ return false;
// It's dead, so we can just remove it now and create the new record.
ctx.m_dataMap.erase(i);
}
ctx.m_dataMap[key]=Record(value,expiration);
m_log.debug("inserted record (%s) in context (%s)", key, context);
+ return true;
}
int MemoryStorageService::readString(const char* context, const char* key, string* pvalue, time_t* pexpiration, int version)
* @param key null-terminated unique key of up to 255 bytes
* @param value null-terminated value of up to 255 bytes to store
* @param expiration an expiration timestamp, after which the record can be purged
+ * @return true iff record was inserted, false iff a duplicate was found
*
- * @throws IOException raised if errors occur in the insertion process
+ * @throws IOException raised if fatal errors occur in the insertion process
*/
- virtual void createString(const char* context, const char* key, const char* value, time_t expiration)=0;
+ virtual bool createString(const char* context, const char* key, const char* value, time_t expiration)=0;
/**
* Returns an existing "short" record from the storage service.
* @param key null-terminated unique key of up to 255 bytes
* @param value null-terminated value of arbitrary length
* @param expiration an expiration timestamp, after which the record can be purged
+ * @return true iff record was inserted, false iff a duplicate was found
*
* @throws IOException raised if errors occur in the insertion process
*/
- virtual void createText(const char* context, const char* key, const char* value, time_t expiration)=0;
+ virtual bool createText(const char* context, const char* key, const char* value, time_t expiration)=0;
/**
* Returns an existing "long" record from the storage service.