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

add redis implementation, add support for multiple cache providers #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Mateusz512
Copy link
Contributor

Description

Add Redis as cache provider and refactor the module so that multiple providers are possible.

Motivation and Context

Redis is nice to have out of the box. Also with the following changes, adding a new cache provider is trivial.

Screenshots (if appropriate)

Upgrade notes (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

I hereby agree to the terms of the Knot.x Contributor License Agreement.

Copy link
Contributor

@marcinkp marcinkp left a comment

Choose a reason for hiding this comment

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

How about one general unit test for CacheAction with dummy Cache implementation?

@marcinkp
Copy link
Contributor

marcinkp commented Nov 6, 2019

I would suggest implement unit test for CacheAction with mock Cache implementation.

also two seperate tests for InMemoryCache and RedisCache.

Please update also a documentation

Copy link
Member

@malaskowski malaskowski left a comment

Choose a reason for hiding this comment

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

Could you please provide some documentation for the new Redis cache?
Also, please update the changelog.

@Voycawojka
Copy link
Contributor

This PR is untouched since november. Is it still valid?

private RedisOptions getRedisOptions(JsonObject config) {
return Optional.ofNullable(config.getJsonObject("redis"))
.map(this::toRedisOptions)
.orElseGet(RedisOptions::new);
Copy link
Contributor

@marcinus marcinus Mar 26, 2020

Choose a reason for hiding this comment

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

Seems to be an invalid case?


return new RedisOptions()
.setEndpoint(SocketAddress.inetSocketAddress(port, host))
.setPassword(password);
Copy link
Contributor

Choose a reason for hiding this comment

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

validate if acceptable


private static final int DEFAULT_PORT = 6379;

private static final long DEFAULT_TTL = 60;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Better move to config object?

public void put(String key, Object value) {
if (value instanceof JsonObject || value instanceof JsonArray || value instanceof String) {
String valueToBeCached = value.toString();
redis.setex(key, Long.toString(ttl), valueToBeCached, response -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

validate if Vert.x Redis Client ensures FIFO behaviour when creating cache entries


private void callDoActionAndCache(FragmentContext fragmentContext,
Handler<AsyncResult<FragmentResult>> resultHandler, String cacheKey) {
doAction.apply(fragmentContext, asyncResult -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to rxified Action interface

cache.put(cacheKey, resultPayload.getMap()
.get(payloadKey));
}
Future.succeededFuture(fragmentResult)
Copy link
Contributor

Choose a reason for hiding this comment

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

consider whether this should be configurable

Copy link
Contributor

Choose a reason for hiding this comment

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

what if doAction specifies a _fallback transition, but there is something that could be cached?
In general: what is the approach for handling decorated actions' results/transitions

Fragment fragment = fragmentContext.getFragment();
FragmentResult result = new FragmentResult(fragment, FragmentResult.ERROR_TRANSITION);
Future.succeededFuture(result)
.setHandler(resultHandler);
Copy link
Contributor

@marcinus marcinus Mar 26, 2020

Choose a reason for hiding this comment

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

Consider if this should be configurable? Should cache failure always mean general failure, or perhaps just some throttling would be acceptable?

.orElse(null);
}

private static Object valueToObject(String value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to commons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants