4
votes

Deleting a row after certain time:

I am inserting notification in table. If it is unread it will be there , if it is read it should be deleted after 1week. How will i achieve that?

I am using TTL but it seems it only expire Column not row.

I want to delete row.

2

2 Answers

2
votes

Create a second CF (called eg. recorded, same key semantics as the notifications table) that you insert (w/ TTL) seen messages into. At the same time you delete the same message from the notifications table.

To load an inbox you need to read from both CF. Seen messages will automatically be removed after 1 week and unseen messages will stick around for ever.

2
votes

See:

https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_expire_c.html

Example:

INSERT INTO users
            (user_name, password)
            VALUES ('cbrown', 'ch@ngem4a') USING TTL 86400;