Binary Data Service
The Binary Data Service is an abstraction that hides the complexity of storing and retrieving binary data using configurable providers.
Uses the concept of sessions to buckets in order to give a logical separation between different scopes. For example, "config" could be a bucket to store all data related to the configurations scope, and it will be represented as a folder in the local file system provider.
@Inject
protected BinaryDataService binaryDataService;
protected BinaryDataServiceSession session;
@PostConstruct
void init() {
session = binaryDataService.newSession("config");
}
public void storeConfig(String key, InputStream inputStream) {
session.store(key, inputStream);
}
public Optional<InputStream> findConfig(String key) {
return session.find(key);
}
Providers
Local File System
The default provider. Uses the local file system, or any mounted drive as the storage:
storage:
binary:
provider: local
dataPath: other
Configuration parameters:
storage.binary.provider
(Optional, String) If given, must be local
.
storage.binary.dataPath
(Optional, String) The path where the data will be stored. Default is ${tmp}/binary
,
where ${tmp}
is the default temporary folder of the OS where the application runs.
SFTP
Uses a remote SFTP server as storage:
storage:
binary:
provider: sftp
dataPath: other
server: sftp://user:pass@localhost:22
connection:
keepAliveInterval: 1m
connectTimeout: 30s
readTimeout: 30s
Keep in mind that SFTP is known to be slow. Use it only as last resource
Configuration parameters:
storage.binary.provider
(Required, String) Must be sftp
.
storage.binary.dataPath
(Optional, String) The path where the data will be stored. Default is /binary
.
storage.binary.server
(Optional, String) The URI to the SFTP server. Default is sftp://pdp:pdp@localhost:22
.
storage.binary.connection.keepAliveInterval
(Optional, Duration) The interval to send a keep alive signal to the server. Default is 30s
.
storage.binary.connection.connectTimeout
(Optional, Duration) The timeout for the connection to the server. Default is 5s
.
storage.binary.connection.readTimeout
(Optional, Duration) The timeout for the reading from the server. Default is 3s
.
Cache Manager
The local cache is an extension to the one provided by Micronaut and implemented with Caffeine.
It simplifies the process of caching entities with the use of annotations and configurations in the application.yml
Configuration
storage:
cache:
local:
myEntity:
initialCapacity: 10
maximumSize: 50
maximumWeight: 100
expireAfterWrite: 1h
expireAfterAccess: 5m
recordStats: true
testMode: false
For a cache named myEntity
with the following properties:
| Property | Type | Default | Description | | ----------------- | :------: | :-----: | ----------- | | initialCapacity | Integer | 16 | The minimum size of the cache | | maximumSize | Long | | The maximum size of the cache. Can not be combined with a weigher | | maximumWeight | Long | | The maximum weight to be allowed for an element in the cache (see Weigher section) | | expireAfterWrite | Duration | | The time to wait to expire an element after its creation | | expireAfterAccess | Duration | 5m | The time to wait to expire an element after the last time it was accessed | | recordStats | boolean | true | To record statistics about hit rates and evictions (see Cache Statistics section) | | testMode | boolean | false | To execute all cache operations in a single thread |