Skip to content

Commit d6b507e

Browse files
committed
Functional interfaces for caching and batching
1 parent 6b59060 commit d6b507e

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2016 The original author or authors
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* and Apache License v2.0 which accompanies this distribution.
7+
*
8+
* The Eclipse Public License is available at
9+
* http://www.eclipse.org/legal/epl-v10.html
10+
*
11+
* The Apache License v2.0 is available at
12+
* http://www.opensource.org/licenses/apache2.0.php
13+
*
14+
* You may elect to redistribute this code under either of these licenses.
15+
*/
16+
17+
package io.engagingspaces.vertx.dataloader;
18+
19+
import io.vertx.core.CompositeFuture;
20+
21+
import java.util.Collection;
22+
23+
/**
24+
* Function that is invoked for batch loading the list of data values indicated by the provided list of keys. The
25+
* function returns a {@link CompositeFuture} to aggregate results of individual load requests.
26+
*
27+
* @param <K> type parameter indicating the type of keys to use for data load requests.
28+
*
29+
* @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
30+
*/
31+
@FunctionalInterface
32+
public interface BatchLoader<K> {
33+
34+
/**
35+
* Batch load the provided keys and return a composite future of the result.
36+
*
37+
* @param keys the list of keys to load
38+
* @return the composite future
39+
*/
40+
CompositeFuture load(Collection<K> keys);
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2016 The original author or authors
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* and Apache License v2.0 which accompanies this distribution.
7+
*
8+
* The Eclipse Public License is available at
9+
* http://www.eclipse.org/legal/epl-v10.html
10+
*
11+
* The Apache License v2.0 is available at
12+
* http://www.opensource.org/licenses/apache2.0.php
13+
*
14+
* You may elect to redistribute this code under either of these licenses.
15+
*/
16+
17+
package io.engagingspaces.vertx.dataloader;
18+
19+
/**
20+
* Function that is invoked on input keys of type {@code K} to derive keys that are required by the {@link CacheMap}
21+
* implementation.
22+
*
23+
* @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
24+
*/
25+
@FunctionalInterface
26+
public interface CacheKey {
27+
28+
/**
29+
* Returns the cache key that is created from the provided input key.
30+
*
31+
* @param input the input key
32+
* @param <K> type parameter indicating the type of the input key
33+
* @param <U> type parameter indicating the type of the cache key that is returned
34+
* @return the cache key
35+
*/
36+
<K, U> U getKey(K input);
37+
}

0 commit comments

Comments
 (0)