Support Topics Documentation Slack YouTube Blog

How to achieve some kind of autoexpiry on a data object?

I want to know how to create some kind of auto-expiration feature on a data object within a table.
For example, when I create a new data object, then this object will self-destruct/remove within a specific period/timeframe.

Can this be achieved with Backendless?
If so, how can it be done? Can anyone help?

Thanks.

Create a timer using Business Logic (Cloud Code). The timer would use the bulk delete API using a query for the created or updated columns (depending on which objects you need to delete)

Thanks Mark for such a fast and amazing response, as always.

By the way, doesn’t Backendless limit on how many timers an app can have?
If there are too many objects, then we may quickly hit the timers limit.

I see when using the timer we must specify the start date.
Can the start date is specified from the date/when the object is created?
And then it will expire within 15 minutes, for example.

Can we create a timer from event handlers?
For example, every time an object is created etc. then create a timer for auto-expiry.
Is that possible?

I would create one timer that does the clean up for all of your tables.

There is a limit for the number of “cloud code scripts” (see it in the pricing table). A timer is consider such a script. That limit can be increased with a purchase of “unlimited cloud code scripts” from the marketplace:

Another limit to consider is the “cloud code execution time” - this is the timer the platform gives to your time to do its job. That limit can also be increased through the marketplace:

That would be an overkill. A single timer can do the clean up for the entire table. Suppose the timer runs once a minute (or hour, or day) and deletes all objects which expire by then.

I do not want to clean up entire table. I just want to self-expire/self-remove/self-destruct an object/some objects after specific period, for example 15 minutes. Cleaning the table up within a timer would be easy, but that is not what I want to achieve.

You do not need to delete the entire table. Using the bulk delete API (did you check the doc link I sent?) you can delete only the objects which match the query.

For example, here’s a where clause query which can be used in the bulk delete API. This query will identify the objects created before May 24th 2017. The bulk delete operation will delete only those objects.

created < '05-24-2017'

Suppose you have a column that is called expired. Then you can create a where clause query for the bulk delete API that looks like this:

expired = true

Makes sense?