Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Rename module-cache to pbc-storage #3330

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/config-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ See [metrics documentation](metrics.md) for complete list of metrics submitted a
- `cache.scheme` - set the external Cache Service protocol: `http`, `https`, etc.
- `cache.host` - set the external Cache Service destination in format `host:port`.
- `cache.path` - set the external Cache Service path, for example `/cache`.
- `cache.module.enabled` - If set to true, this will allow storing modules’ data in third-party storage.
- `cache.module.path` - set the external Cache Service path for module caching, for example `/module/cache`.
- `cache.api.key` - set the external Cache Service api key for secured calls.
- `storage.pbc.enabled` - If set to true, this will allow storing modules’ data in third-party storage.
- `storage.pbc.path` - set the external Cache Service path for module caching, for example `/pbc-storage`.
- `pbc.api.key` - set the external Cache Service api key for secured calls.
- `cache.query` - appends to the cache path as query string params (used for legacy Auction requests).
- `cache.banner-ttl-seconds` - how long (in seconds) banner will be available via the external Cache Service.
- `cache.video-ttl-seconds` - how long (in seconds) video creative will be available via the external Cache Service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.cache.proto.request.module.ModuleCacheRequest;
import org.prebid.server.cache.proto.request.module.ModuleCacheType;
import org.prebid.server.cache.proto.request.module.StorageDataType;
import org.prebid.server.cache.proto.response.module.ModuleCacheResponse;
import org.prebid.server.cache.utils.CacheServiceUtil;
import org.prebid.server.exception.PreBidException;
Expand All @@ -17,7 +17,7 @@
import java.net.URL;
import java.util.Objects;

public class BasicModuleCacheService implements ModuleCacheService {
public class BasicPbcStorageService implements PbcStorageService {

public static final String MODULE_KEY_PREFIX = "module";
public static final String MODULE_KEY_DELIMETER = ".";
Expand All @@ -28,11 +28,11 @@ public class BasicModuleCacheService implements ModuleCacheService {
private final int callTimeoutMs;
private final JacksonMapper mapper;

public BasicModuleCacheService(HttpClient httpClient,
URL endpointUrl,
String apiKey,
int callTimeoutMs,
JacksonMapper mapper) {
public BasicPbcStorageService(HttpClient httpClient,
URL endpointUrl,
String apiKey,
int callTimeoutMs,
JacksonMapper mapper) {

this.httpClient = Objects.requireNonNull(httpClient);
this.endpointUrl = Objects.requireNonNull(endpointUrl);
Expand All @@ -42,12 +42,12 @@ public BasicModuleCacheService(HttpClient httpClient,
}

@Override
public Future<Void> storeModuleEntry(String key,
String value,
ModuleCacheType type,
Integer ttlseconds,
String application,
String moduleCode) {
public Future<Void> storeEntry(String key,
String value,
StorageDataType type,
Integer ttlseconds,
String application,
String moduleCode) {

try {
validateStoreData(key, value, application, type, moduleCode);
Expand Down Expand Up @@ -75,7 +75,7 @@ public Future<Void> storeModuleEntry(String key,
private static void validateStoreData(String key,
String value,
String application,
ModuleCacheType type,
StorageDataType type,
String moduleCode) {

if (StringUtils.isBlank(key)) {
Expand All @@ -99,8 +99,8 @@ private static void validateStoreData(String key,
}
}

private static String prepareValueForStoring(String value, ModuleCacheType type) {
return type == ModuleCacheType.TEXT
private static String prepareValueForStoring(String value, StorageDataType type) {
return type == StorageDataType.TEXT
? new String(Base64.encodeBase64(value.getBytes()))
: value;
}
Expand Down Expand Up @@ -186,8 +186,8 @@ private ModuleCacheResponse toModuleCacheResponse(int statusCode, String respons
: ModuleCacheResponse.of(moduleCacheResponse.getKey(), moduleCacheResponse.getType(), processedValue);
}

private static String prepareValueAfterRetrieve(String value, ModuleCacheType type) {
return type == ModuleCacheType.TEXT
private static String prepareValueAfterRetrieve(String value, StorageDataType type) {
return type == StorageDataType.TEXT
? new String(Base64.decodeBase64(value.getBytes()))
: value;
}
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/org/prebid/server/cache/ModuleCacheService.java

This file was deleted.

40 changes: 40 additions & 0 deletions src/main/java/org/prebid/server/cache/PbcStorageService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.prebid.server.cache;

import io.vertx.core.Future;
import org.prebid.server.cache.proto.request.module.StorageDataType;
import org.prebid.server.cache.proto.response.module.ModuleCacheResponse;

public interface PbcStorageService {

Future<Void> storeEntry(String key,
String value,
StorageDataType type,
Integer ttlseconds,
String application,
String moduleCode);

Future<ModuleCacheResponse> retrieveModuleEntry(String key, String moduleCode, String application);

static NoOpPbcStorageService noOp() {
return new NoOpPbcStorageService();
}

class NoOpPbcStorageService implements PbcStorageService {

@Override
public Future<Void> storeEntry(String key,
String value,
StorageDataType type,
Integer ttlseconds,
String application,
String moduleCode) {

return Future.succeededFuture();
}

@Override
public Future<ModuleCacheResponse> retrieveModuleEntry(String key, String moduleCode, String application) {
return Future.succeededFuture(ModuleCacheResponse.empty());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ModuleCacheRequest {

String key;

ModuleCacheType type;
StorageDataType type;

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonValue;

public enum ModuleCacheType {
public enum StorageDataType {

JSON("json"),
XML("xml"),
Expand All @@ -11,7 +11,7 @@ public enum ModuleCacheType {
@JsonValue
private final String text;

ModuleCacheType(String text) {
StorageDataType(String text) {
this.text = text;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.prebid.server.cache.proto.response.module;

import lombok.Value;
import org.prebid.server.cache.proto.request.module.ModuleCacheType;
import org.prebid.server.cache.proto.request.module.StorageDataType;

@Value(staticConstructor = "of")
public class ModuleCacheResponse {

String key;

ModuleCacheType type;
StorageDataType type;

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
import org.prebid.server.bidder.BidderRequestCompletionTrackerFactory;
import org.prebid.server.bidder.HttpBidderRequestEnricher;
import org.prebid.server.bidder.HttpBidderRequester;
import org.prebid.server.cache.BasicModuleCacheService;
import org.prebid.server.cache.BasicPbcStorageService;
import org.prebid.server.cache.CoreCacheService;
import org.prebid.server.cache.ModuleCacheService;
import org.prebid.server.cache.PbcStorageService;
import org.prebid.server.cache.model.CacheTtl;
import org.prebid.server.cache.utils.CacheServiceUtil;
import org.prebid.server.cookie.CookieDeprecationService;
Expand Down Expand Up @@ -183,22 +183,22 @@ CoreCacheService cacheService(

@Bean
@ConditionalOnProperty(prefix = "cache.module", name = "enabled", havingValue = "false", matchIfMissing = true)
ModuleCacheService noOpModuleCacheService() {
return ModuleCacheService.noOp();
PbcStorageService noOpModuleCacheService() {
return PbcStorageService.noOp();
}

@Bean
@ConditionalOnProperty(prefix = "cache.module", name = "enabled", havingValue = "true")
ModuleCacheService basicModuleCacheService(
PbcStorageService basicModuleCacheService(
@Value("${cache.scheme}") String scheme,
@Value("${cache.host}") String host,
@Value("${cache.module.path}") String path,
@Value("${cache.module.call-timeout-ms}") int callTimeoutMs,
@Value("${cache.api.key}") String apiKey,
@Value("${storage.pbc.path}") String path,
@Value("${storage.pbc.call-timeout-ms}") int callTimeoutMs,
@Value("${pbc.api.key}") String apiKey,
HttpClient httpClient,
JacksonMapper mapper) {

return new BasicModuleCacheService(
return new BasicPbcStorageService(
httpClient,
CacheServiceUtil.getCacheEndpointUrl(scheme, host, path),
apiKey,
Expand Down
Loading
Loading