Skip to content

Commit a8e0f6d

Browse files
authored
Merge pull request #397 from HarperFast/update-scanInterval-description
add detailed scanInterval description
2 parents 9edb502 + 0dbc936 commit a8e0f6d

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

docs/developers/applications/caching.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ You can provide a single expiration and it defines the behavior for all three. Y
2626
- `eviction` - The amount of time after expiration before a record can be evicted (defaults to zero).
2727
- `scanInterval` - The interval for scanning for expired records (defaults to one quarter of the total of expiration and eviction).
2828

29+
#### How `scanInterval` Determines the Eviction Cycle
30+
31+
`scanInterval` determines fixed clock-aligned times when eviction runs, and these times are the same regardless of when the server started. Harper takes the `scanInterval` and divides the TTL (`expiration` + `eviction`) into evenly spacedanchor times.” These anchors are calculated in the local timezone of the server. This allows Harper tosnapthe eviction schedule to predictable points on the clock, such as every 15 minutes or every 6 hours, based on the interval length. As a result:
32+
33+
- The servers startup time does not affect when eviction runs.
34+
- Eviction timings are deterministic and timezone-aware.
35+
- For any given configuration, the eviction schedule is the same across restarts and across servers in the same local timezone.
36+
37+
#### Example: 1-Hour Expiration
38+
39+
`expiration` = 1 hour with default `scanInterval` (15 minutes, one quarter of `expiration`). This creates the following fixed eviction schedule:
40+
41+
> 00:00
42+
> 00:15
43+
> 00:30
44+
> 00:45
45+
> 01:00
46+
> ... continuing every 15 minutes ...
47+
48+
If the server starts at 12:05 it does not run eviction at 12:20 or “15 minutes after startup.” Instead, the next scheduled anchor is 12:15, then 12:30, 12:45, 13:00, etc. The schedule is clock-aligned, not startup-aligned.
49+
50+
#### Example: 1-Day Expiration
51+
52+
`expiration` = 1 day with default `scanInterval` (6 hours, one quarter of `expiration`). This creates the following fixed eviction schedule:
53+
54+
> 00:00
55+
> 06:00
56+
> 12:00
57+
> 18:00
58+
> ... continuing every 6 hours ...
59+
60+
If the server starts at 12:05 the next matching eviction time is 18:00 the same day, then 00:00, 06:00, 12:00, 18:00, etc. If the server starts at 19:30 the schedule does not shift. Instead, the next anchor time is 00:00, and the regular 6-hour cycle continues.
61+
2962
## Define External Data Source
3063

3164
Next, you need to define the source for your cache. External data sources could be HTTP APIs, other databases, microservices, or any other source of data. This can be defined as a resource class in your application's `resources.js` module. You can extend the `Resource` class (which is available as a global variable in the Harper environment) as your base class. The first method to implement is a `get()` method to define how to retrieve the source data. For example, if we were caching an external HTTP API, we might define it as such:

versioned_docs/version-4.5/developers/applications/caching.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ You can provide a single expiration and it defines the behavior for all three. Y
2626
- `eviction` - The amount of time after expiration before a record can be evicted (defaults to zero).
2727
- `scanInterval` - The interval for scanning for expired records (defaults to one quarter of the total of expiration and eviction).
2828

29+
#### How `scanInterval` Determines the Eviction Cycle
30+
31+
`scanInterval` determines fixed clock-aligned times when eviction runs, and these times are the same regardless of when the server started. Harper takes the `scanInterval` and divides the TTL (`expiration` + `eviction`) into evenly spacedanchor times.” These anchors are calculated in the local timezone of the server. This allows Harper tosnapthe eviction schedule to predictable points on the clock, such as every 15 minutes or every 6 hours, based on the interval length. As a result:
32+
33+
- The servers startup time does not affect when eviction runs.
34+
- Eviction timings are deterministic and timezone-aware.
35+
- For any given configuration, the eviction schedule is the same across restarts and across servers in the same local timezone.
36+
37+
#### Example: 1-Hour Expiration
38+
39+
`expiration` = 1 hour with default `scanInterval` (15 minutes, one quarter of `expiration`). This creates the following fixed eviction schedule:
40+
41+
> 00:00
42+
> 00:15
43+
> 00:30
44+
> 00:45
45+
> 01:00
46+
> ... continuing every 15 minutes ...
47+
48+
If the server starts at 12:05 it does not run eviction at 12:20 or “15 minutes after startup.” Instead, the next scheduled anchor is 12:15, then 12:30, 12:45, 13:00, etc. The schedule is clock-aligned, not startup-aligned.
49+
50+
#### Example: 1-Day Expiration
51+
52+
`expiration` = 1 day with default `scanInterval` (6 hours, one quarter of `expiration`). This creates the following fixed eviction schedule:
53+
54+
> 00:00
55+
> 06:00
56+
> 12:00
57+
> 18:00
58+
> ... continuing every 6 hours ...
59+
60+
If the server starts at 12:05 the next matching eviction time is 18:00 the same day, then 00:00, 06:00, 12:00, 18:00, etc. If the server starts at 19:30 the schedule does not shift. Instead, the next anchor time is 00:00, and the regular 6-hour cycle continues.
61+
2962
## Define External Data Source
3063

3164
Next, you need to define the source for your cache. External data sources could be HTTP APIs, other databases, microservices, or any other source of data. This can be defined as a resource class in your application's `resources.js` module. You can extend the `Resource` class (which is available as a global variable in the Harper environment) as your base class. The first method to implement is a `get()` method to define how to retrieve the source data. For example, if we were caching an external HTTP API, we might define it as such:

versioned_docs/version-4.6/developers/applications/caching.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ You can provide a single expiration and it defines the behavior for all three. Y
2626
- `eviction` - The amount of time after expiration before a record can be evicted (defaults to zero).
2727
- `scanInterval` - The interval for scanning for expired records (defaults to one quarter of the total of expiration and eviction).
2828

29+
#### How `scanInterval` Determines the Eviction Cycle
30+
31+
`scanInterval` determines fixed clock-aligned times when eviction runs, and these times are the same regardless of when the server started. Harper takes the `scanInterval` and divides the TTL (`expiration` + `eviction`) into evenly spacedanchor times.” These anchors are calculated in the local timezone of the server. This allows Harper tosnapthe eviction schedule to predictable points on the clock, such as every 15 minutes or every 6 hours, based on the interval length. As a result:
32+
33+
- The servers startup time does not affect when eviction runs.
34+
- Eviction timings are deterministic and timezone-aware.
35+
- For any given configuration, the eviction schedule is the same across restarts and across servers in the same local timezone.
36+
37+
#### Example: 1-Hour Expiration
38+
39+
`expiration` = 1 hour with default `scanInterval` (15 minutes, one quarter of `expiration`). This creates the following fixed eviction schedule:
40+
41+
> 00:00
42+
> 00:15
43+
> 00:30
44+
> 00:45
45+
> 01:00
46+
> ... continuing every 15 minutes ...
47+
48+
If the server starts at 12:05 it does not run eviction at 12:20 or “15 minutes after startup.” Instead, the next scheduled anchor is 12:15, then 12:30, 12:45, 13:00, etc. The schedule is clock-aligned, not startup-aligned.
49+
50+
#### Example: 1-Day Expiration
51+
52+
`expiration` = 1 day with default `scanInterval` (6 hours, one quarter of `expiration`). This creates the following fixed eviction schedule:
53+
54+
> 00:00
55+
> 06:00
56+
> 12:00
57+
> 18:00
58+
> ... continuing every 6 hours ...
59+
60+
If the server starts at 12:05 the next matching eviction time is 18:00 the same day, then 00:00, 06:00, 12:00, 18:00, etc. If the server starts at 19:30 the schedule does not shift. Instead, the next anchor time is 00:00, and the regular 6-hour cycle continues.
61+
2962
## Define External Data Source
3063

3164
Next, you need to define the source for your cache. External data sources could be HTTP APIs, other databases, microservices, or any other source of data. This can be defined as a resource class in your application's `resources.js` module. You can extend the `Resource` class (which is available as a global variable in the Harper environment) as your base class. The first method to implement is a `get()` method to define how to retrieve the source data. For example, if we were caching an external HTTP API, we might define it as such:

versioned_docs/version-4.7/developers/applications/caching.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ You can provide a single expiration and it defines the behavior for all three. Y
2626
- `eviction` - The amount of time after expiration before a record can be evicted (defaults to zero).
2727
- `scanInterval` - The interval for scanning for expired records (defaults to one quarter of the total of expiration and eviction).
2828

29+
#### How `scanInterval` Determines the Eviction Cycle
30+
31+
`scanInterval` determines fixed clock-aligned times when eviction runs, and these times are the same regardless of when the server started. Harper takes the `scanInterval` and divides the TTL (`expiration` + `eviction`) into evenly spacedanchor times.” These anchors are calculated in the local timezone of the server. This allows Harper tosnapthe eviction schedule to predictable points on the clock, such as every 15 minutes or every 6 hours, based on the interval length. As a result:
32+
33+
- The servers startup time does not affect when eviction runs.
34+
- Eviction timings are deterministic and timezone-aware.
35+
- For any given configuration, the eviction schedule is the same across restarts and across servers in the same local timezone.
36+
37+
#### Example: 1-Hour Expiration
38+
39+
`expiration` = 1 hour with default `scanInterval` (15 minutes, one quarter of `expiration`). This creates the following fixed eviction schedule:
40+
41+
> 00:00
42+
> 00:15
43+
> 00:30
44+
> 00:45
45+
> 01:00
46+
> ... continuing every 15 minutes ...
47+
48+
If the server starts at 12:05 it does not run eviction at 12:20 or “15 minutes after startup.” Instead, the next scheduled anchor is 12:15, then 12:30, 12:45, 13:00, etc. The schedule is clock-aligned, not startup-aligned.
49+
50+
#### Example: 1-Day Expiration
51+
52+
`expiration` = 1 day with default `scanInterval` (6 hours, one quarter of `expiration`). This creates the following fixed eviction schedule:
53+
54+
> 00:00
55+
> 06:00
56+
> 12:00
57+
> 18:00
58+
> ... continuing every 6 hours ...
59+
60+
If the server starts at 12:05 the next matching eviction time is 18:00 the same day, then 00:00, 06:00, 12:00, 18:00, etc. If the server starts at 19:30 the schedule does not shift. Instead, the next anchor time is 00:00, and the regular 6-hour cycle continues.
61+
2962
## Define External Data Source
3063

3164
Next, you need to define the source for your cache. External data sources could be HTTP APIs, other databases, microservices, or any other source of data. This can be defined as a resource class in your application's `resources.js` module. You can extend the `Resource` class (which is available as a global variable in the Harper environment) as your base class. The first method to implement is a `get()` method to define how to retrieve the source data. For example, if we were caching an external HTTP API, we might define it as such:

0 commit comments

Comments
 (0)