|
3 | 3 |
|
4 | 4 | {NOTE: }
|
5 | 5 |
|
6 |
| -* The Expiration feature deletes expired documents, documents whose time has passed. |
7 |
| - Documents that are set with a future expiration time will be automatically deleted. |
8 |
| - |
9 |
| -* The Expiration feature can be turned on and off while the database is already live with data. |
| 6 | +* Documents can be given a future expiration time in which they'll be automatically deleted. |
| 7 | +* The Expiration feature deletes documents set for expiration, when their time has passed. |
| 8 | +* You can enable or disable the expiration feature while the database is already live with data. |
10 | 9 |
|
11 | 10 | * In this page:
|
12 | 11 | * [Expiration feature usages](../../server/extensions/expiration#expiration-feature-usages)
|
13 | 12 | * [Configuring the expiration feature](../../server/extensions/expiration#configuring-the-expiration-feature)
|
| 13 | + * [Configure expiration settings using the client API](../../server/extensions/expiration#configure-expiration-settings-using-the-client-api) |
14 | 14 | * [Setting the document expiration time](../../server/extensions/expiration#setting-the-document-expiration-time)
|
15 | 15 | * [Eventual consistency considerations](../../server/extensions/expiration#eventual-consistency-considerations)
|
16 |
| - * [More details](../../server/extensions/expiration#more-details) |
17 | 16 | {NOTE/}
|
18 | 17 |
|
19 | 18 | ---
|
20 | 19 |
|
21 | 20 | {PANEL: Expiration feature usages}
|
22 | 21 |
|
23 |
| -* Use the Expiration feature when data is needed to be kept for only a temporary time. |
| 22 | +Use the Expiration feature when data is needed only for a given time period. |
| 23 | +E.g., for - |
| 24 | + |
| 25 | + * Shopping cart data that is kept only for a certain time period |
| 26 | + * Email links that need to be expired after a few hours |
| 27 | + * A web application login session details |
| 28 | + * Cache data from an SQL server |
24 | 29 |
|
25 |
| -* Examples: |
26 |
| - * Shopping cart data that is kept for only a specific time |
27 |
| - * Email links that need to be expired after a few hours |
28 |
| - * Storing a web application login session details |
29 |
| - * When using RavenDB to hold cache data from a SQL server. |
30 | 30 | {PANEL/}
|
31 | 31 |
|
32 | 32 | {PANEL: Configuring the expiration feature}
|
33 | 33 |
|
34 |
| -* By default, the expiration feature is turned off. |
| 34 | +Documents expiration settings can be changed via Studio or the API. |
| 35 | +It is possible to: |
35 | 36 |
|
36 |
| -* The delete frequency is configurable, the default value is 60 secs. |
| 37 | +* Enable or Disable the deletion of expired documents. |
| 38 | + Default value: **Disable** the deletion of expired documents. |
| 39 | +* Determine how often RavenDB would look for expired documents and delete them. |
| 40 | + Default value: **60 seconds** |
| 41 | +* Set the maximal number of documents that RavenDB is allowed to delete per interval. |
| 42 | + Default value: **All expired documents** |
37 | 43 |
|
38 |
| -* The Expiration feature can be turned on and off using **Studio**, see [Setting Document Expiration in Studio](../../studio/database/settings/document-expiration). |
| 44 | +--- |
39 | 45 |
|
40 |
| -* The Expiration feature can also be configured using the **Client**: |
| 46 | +{INFO: } |
| 47 | +[Learn how to configure expiration settings via Studio](../../studio/database/settings/document-expiration) |
| 48 | +{INFO/} |
41 | 49 |
|
42 |
| -{CODE configuration@Server\Expiration\Expiration.cs /} |
43 |
| -{PANEL/} |
| 50 | +--- |
44 | 51 |
|
45 |
| -{PANEL: Setting the document expiration time} |
| 52 | +### Configure expiration settings using the client API |
46 | 53 |
|
47 |
| -* To set the document expiration time just add the `@expires` property to the document `@metadata` and set it to contain the appropriate expiration time. |
| 54 | +Modify the expiration settings using the client API by setting an `ExpirationConfiguration` |
| 55 | +object and sending it to RavenDB using a `ConfigureExpirationOperation` operation. |
48 | 56 |
|
49 |
| -* Once the Expiration feature is enabled, the document will automatically be deleted at the specified time. |
| 57 | +#### Example: |
50 | 58 |
|
51 |
| -* **Note**: The date must be in **UTC** format, not local time. |
| 59 | +{CODE configuration@Server\Expiration\Expiration.cs /} |
| 60 | + |
| 61 | +#### `ExpirationConfiguration` |
| 62 | + |
| 63 | +{CODE expirationConfiguration@Server\Expiration\Expiration.cs /} |
52 | 64 |
|
53 |
| -* The document expiration time can be set using the following code from the client: |
| 65 | +| Parameter | Type | Description | |
| 66 | +| - | - | - | |
| 67 | +| **Disabled** | `bool` | If `true`, deleting expired documents is disabled for the entire database.<BR>Default: `true` | |
| 68 | +| **DeleteFrequencyInSec** | `long?` | Determines how often (in seconds) the expiration feature looks for expired documents and deletes them.<BR>Default: `60` | |
| 69 | +| **MaxItemsToProcess** | `long?` | Determines the maximal number of documents the feature is allowed to delete in one run. | |
54 | 70 |
|
55 |
| -{CODE expiration1@Server\Expiration\Expiration.cs /} |
56 | 71 | {PANEL/}
|
57 | 72 |
|
58 |
| -{PANEL: Eventual consistency considerations} |
| 73 | +{PANEL: Setting the document expiration time} |
59 | 74 |
|
60 |
| -* Once documents are expired, it can take up to the delete frequency interval (60 seconds by default) until these expired documents are actually deleted. |
| 75 | +* To set a document expiration time, add the document's `@metadata` an |
| 76 | + `@expires` property with the designated expiration time as a value. |
| 77 | + Set the time in **UTC** format, not local time. E.g. - |
| 78 | + **"@expires": "2025-04-22T08:00:00.0000000Z"** |
| 79 | + {WARNING: } |
| 80 | + Metadata properties starting with `@` are for internal RavenDB usage only. |
| 81 | + Do _not_ use the metadata `@expires` property for any other purpose than |
| 82 | + scheduling a document's expiration time for the built-in expiration feature. |
| 83 | + {WARNING/} |
| 84 | +* If and when the expiration feature is enabled, it will process all documents |
| 85 | + carrying the `@expires` flag and automatically delete each document |
| 86 | + [by its expiration time](../../server/extensions/expiration#eventual-consistency-considerations). |
| 87 | +* To set the document expiration time from the client, use the following code: |
| 88 | + {CODE expiration1@Server\Expiration\Expiration.cs /} |
61 | 89 |
|
62 |
| -* Expired documents are _not_ filtered on load/query/indexing time, so be aware that an expired document might still be there after it has expired up to the 'delete frequency interval' timeframe. |
63 | 90 | {PANEL/}
|
64 | 91 |
|
65 |
| -{PANEL: More details} |
| 92 | +{PANEL: Eventual consistency considerations} |
66 | 93 |
|
67 |
| -* Internally, each document that has the `@expires` property in the metadata is tracked by the RavenDB server |
68 |
| - even if the expiration feature is turned off. |
69 |
| -This way, once the expiration feature is turned on we can easily delete all the expired documents. |
| 94 | +* Internally, RavenDB tracks all documents carrying the `@expires` flag even if the |
| 95 | + expiration feature is disabled. This way, once the expiration feature is enabled expired |
| 96 | + documents can be processed without delay. |
| 97 | +* Once a document expires, it may take up to the _delete frequency interval_ (60 seconds by default) |
| 98 | + until is it actually deleted. |
| 99 | +* Deletion may be further delayed if `MaxItemsToProcess` is set, limiting the number |
| 100 | + of documents that RavenDB is allowed to delete each time the expiration feature is invoked. |
| 101 | +* Expired documents are _not_ filtered out during `load`, `query`, or indexing, so be aware that |
| 102 | + as long as an expired document hasn't been actually deleted it may still be included in the results. |
70 | 103 |
|
71 |
| -* **Note**: Metadata properties starting with `@` are internal for RavenDB usage. |
72 |
| -You should _not_ use the `@expires` property in the metadata for any other purpose other than the built-in expiration feature. |
73 | 104 | {PANEL/}
|
74 | 105 |
|
75 | 106 | ## Related Articles
|
|
0 commit comments