Lifetime Management
###################

.. program:: jetstream server

.. _lifetime_management#garbage_collection:

Automatic Clean Up
==================

In order to maintain its memory use, the JetStream server cleans up unused objects. This process cleans up the following objects once they have expired: 

============ =================
Object       Expiration Policy
============ =================
Transfers    48 hours after the transfer has completed (or failed).
Manifests    48 hours after creation unless a *Transfer* or *Shared link* still refers to it.
Shared links Once it's time limit, as set in :meth:`~jetstream.sendinterface.SendInterface.createSharedToken`, has been reached.
============ =================

By default, clean up process runs hourly, removing objects that have been unused or expired for 48 hours. The clean up interval and object expiration time limit can be adjusted using the :meth:`~jetstream.serverinterface.ServerInterface.updateGarbageCollectSettings` API function. Clean up can be triggered instantly using the :meth:`~jetstream.serverinterface.ServerInterface.garbageCollect` API function.

The server's current settings can be read from :ref:`jetstream-api:structure-server-info-configuration-garbagecollect` from the :meth:`~jetstream.serverinterface.ServerInterface.getServerInfo` API function.


Persistence
===========

Some objects are preserved across restarts of the server, so long as a persistent state directory is specified (the server is started with :option:`--persistent-state-dir`):

============ ==============
Object       Storage Policy
============ ==============
Destinations Stored unless :option:`--persistent-destinations` is set to ``false``.
Transfers    Stored unless :option:`--persistent-transfers` is set to ``false``.
Manifests    Stored if referenced by a *Transfer* or *Shared link*.
Shared links Always stored.
============ ==============

These objects will be removed from persistent storage once they are deleted (either explicitly or via :ref:`lifetime_management#garbage_collection`).

.. seealso::
    * :ref:`jetstream#server-options`
    * :doc:`jetstream-api:index`
