Using custom data source

Livebox already comes with three built-in data sources:

  • In-memory LRU data source, that keeps data in memory using Least Recently Used policy.

  • Disk LRU data source, under the hood this uses IgDiskCache. Data is serialized to Json and stored in a file using Least Recently Used policy.

  • Disk persistent data source, data is serialized/deserialized to and from Json and is stored in a file . The file lives until the validator associated with this data source and Livebox key returns false. At that point the data is considered invalid and the file is deleted.

The covers a lot of use cases, however you may want to store data in a different form. To do that you can supply a custom data source when building a Livebox instance.

Let's see how we can use Android's room database to write and read data.