The only safe way to retrieve the last N records inserted is to tag each record with a monotonically increasing sequence number that you can query against later. Your code does that (though your method of maintaining the sequence number needs some flock() protection).
But for doing something like "delete everything older than 24 hours", you'll also need to associate a timestamp with each record. If you were storing your data in a relational table, you'd probably have a column to hold the insert time. But you're using DBM, which complicates things somewhat. You could do something like prepending a timestamp to each value, splitting the timestamp off when necessary. Then, a periodic "delete everything older than 24 hours" scan can work its way through the DBM by sorted key value, splitting off the timestamp from each record and deleting those records that have expired.
In reply to Re: Retrieve last elements of a DB
by dws
in thread Retrieve last elements of a DB
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |