- if (i!=ctx.m_dataMap.end())\r
- throw IOException("attempted to insert a record with duplicate key ($1)", params(1,key));\r
+ if (i!=ctx.m_dataMap.end()) {\r
+ // Not yet expired?\r
+ if (time(NULL) < i->second.expiration)\r
+ throw IOException("attempted to insert a record with duplicate key ($1)", params(1,key));\r
+ // It's dead, so we can just remove it now and create the new record.\r
+ // Now find the reversed index of expiration to key, so we can clear it.\r
+ pair<multimap<time_t,string>::iterator,multimap<time_t,string>::iterator> range =\r
+ ctx.m_expMap.equal_range(i->second.expiration);\r
+ for (; range.first != range.second; ++range.first) {\r
+ if (range.first->second == i->first) {\r
+ ctx.m_expMap.erase(range.first);\r
+ break;\r
+ }\r
+ }\r
+ // And finally delete the record itself.\r
+ ctx.m_dataMap.erase(i);\r
+ }\r