简体   繁体   中英

MySQL FIFO policy based on table size

I have a table in MySQL where arrive continuously data (these data have a timestamp). I'd like to create a FIFO Queue based on the size of the table. I mean, if I set for example 1GB as threshold and the data begin to be stored once I reach 1 GB of capacity I start to delete data in a fifo way. Anyone have any suggestions or have ever done anything similar?

Thank you

I think you are confused on the definition of a FIFO queue. You don't describe any consumer of the queue, only deletions.

It sounds more like a least-recently-used cache, that holds up to 1GB of data, but the "oldest" data is overwritten as new data is inserted.

MySQL is neither a cache nor a queue. MySQL is a database. It is designed to store all the data you insert into it, durably. It has no feature to do automatic deletion.

I suggest you should use a cache server such as redis. It has the feature you are looking for, to evict data if the collection exceeds a fixed size.

See the post: Using Redis as an LRU cache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM