swindon-rs / swindon

An HTTP edge (frontend) server with smart websockets support
Apache License 2.0
100 stars 9 forks source link

Implement TTL for lattice keys #55

Open tailhook opened 7 years ago

tailhook commented 7 years ago

Motivation

This is useful to keep notifications for short-living tasks, but not letting them introduce a memory leak if user sessions are long.

Implementation

The idea is to add expires_in key for lattice keys:

POST /v1/lattice/test-chat-rooms HTTP/1.1
{"shared": {
    "room1": {"last_message_counter": 123,
              "expires_in": 300},
 "private": {
   "7777": {
     "room1": {
       "last_seen_counter": 120,
       "expires_in": 300
     }
  }
}

The TTLs for public and private keys are separate, but for user to see public data both private and public items should be valid.

Questions

  1. Maybe units in "expires_in" ? ("30 sec", "10 min")
  2. Or maybe deadline-style api: "expires_at": "2017-09-05T18:00:00Z"
  3. To be able to enumerate tasks when user went offline, we also need to keep private part of the lattice for as long as expiration time rather than session lifetime