com.networknt.aws.lambda.cache.DynamoDbCacheManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda-native Show documentation
Show all versions of lambda-native Show documentation
A middleware Lambda function that handles all the cross-cutting concerns for the downstream Lambda function.
The newest version!
package com.networknt.aws.lambda.cache;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.*;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.regions.Region;
import com.networknt.aws.lambda.utility.LambdaEnvVariables;
import com.networknt.cache.CacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
/**
* This is the cache manager that can survive the cold start of the lambda function.
*/
public class DynamoDbCacheManager implements CacheManager {
private static final Logger LOG = LoggerFactory.getLogger(DynamoDbCacheManager.class);
private static final String HASH_ID_KEY = "Id";
private static final int TABLE_LIST_LIMIT = 100;
private static final Map tables = new HashMap<>();
private final DynamoDbClient dynamoClient;
boolean tableInitiated;
@Override
public void addCache(String cacheName, long maxSize, long expiryInMinutes) {
if(!doesTableExist(cacheName)) {
LOG.debug("Table does not exist so we need to create it....");
createCacheTable(cacheName);
}
tables.put(cacheName, cacheName);
}
@Override
public Map © 2015 - 2025 Weber Informatics LLC | Privacy Policy