-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
core/src/main/java/net/smyler/terramap/http/CacheStatistics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.smyler.terramap.http; | ||
|
||
/** | ||
* Cache usage statistics. | ||
* | ||
* @param entries number of entries in the cache | ||
* @param size total storage space used by the cache | ||
* @param type the type of cache in use | ||
*/ | ||
public record CacheStatistics(long entries, long size, CacheType type) { | ||
|
||
public enum CacheType { | ||
|
||
/** | ||
* Cache is fully on disk. | ||
*/ | ||
DISK, | ||
|
||
/** | ||
* Cache is fully in memory. | ||
* Should not be used outside of development. | ||
*/ | ||
MEMORY, | ||
|
||
/** | ||
* Cache uses a mix of disk and memory storage. | ||
*/ | ||
HYBRID, | ||
|
||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/java/net/smyler/terramap/http/CachingHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.smyler.terramap.http; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* ALL http implementation used by Terramap should implement caching, | ||
* but may not necessarily expose programmatically for management | ||
* (e.g. if Terramap uses Terra++'s http client, Terra++ takes care of | ||
* cache management). | ||
*/ | ||
public interface CachingHttpClient extends HttpClient { | ||
|
||
/** | ||
* Computes statistics about the current cache usage. | ||
* | ||
* @return a future of the client's cache statistics | ||
*/ | ||
CompletableFuture<CacheStatistics> cacheStatistics(); | ||
|
||
/** | ||
* Performs regular maintenance on cache, removing long stale entries etc. | ||
* | ||
* @return a future containing statistics on the entries that were removed from the cache | ||
*/ | ||
CompletableFuture<CacheStatistics> cacheCleanup(); | ||
|
||
/** | ||
* Fully clears the cache. | ||
* | ||
* @return a future containing statistics on the entries that were removed from the cache | ||
*/ | ||
CompletableFuture<CacheStatistics> cacheClear(); | ||
|
||
} |