Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
*/
public class InMemoryCache implements Cache {

private final com.google.common.cache.Cache<String, String> cache;
private final com.google.common.cache.Cache<String, Object> cache;

public InMemoryCache(long ttlSeconds) {
cache = CacheBuilder.newBuilder().expireAfterAccess(ttlSeconds, TimeUnit.SECONDS).build();
}

@Override
public Optional<String> get(String key) {
String val = cache.getIfPresent(key);
String val = (String) cache.getIfPresent(key);
return Optional.ofNullable(val);
}

public Optional<Object> getObject(String key) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would help here is to turn the Cache into a generic Cache<T>. That would let you avoid using the concrete type in BaseChatbotClientImpl and creating the set/getObject methods.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we can make to use generic type.

Object val = cache.getIfPresent(key);
return Optional.ofNullable(val);
}

Expand All @@ -34,12 +39,20 @@ public void set(String key, String val) {
cache.put(key, val);
}

public void setObject(String key, Object val) {
cache.put(key, val);
}

/**
* This method does not respect the ttlSeconds parameter.
*/
@Override
public void set(String key, String val, long ttlSeconds) {
cache.put(key, val);
set(key, val);
}

public void setObject(String key, Object val, long ttlSeconds) {
setObject(key, val);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RedisCache implements Cache {
private static final Long DEFAULT_TTL_SECONDS = 259140L; // 2 days, 23 hours, 59 minutes

private JedisPool jedisPool;
private long ttlSeconds;
private final long ttlSeconds;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also support storing/retrieving objects in RedisCache implementation.


/**
* This constructor will use the default ttl of 259,140 seconds and will assume standard Redis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ BotResponse startChatSession(RequestConfig config,
ExternalSessionId sessionId,
BotSendMessageRequest requestEnvelope);

Status getHealthStatus();
Status getHealthStatus(RequestConfig config);

SupportedVersions getSupportedVersions();
SupportedVersions getSupportedVersions(RequestConfig config);

/**
* BasicClientFluentBuilder provides Fluent API to create Basic Chatbot Client.
Expand Down
Loading