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

Introduce a cache storage SPI #67

Open
tsegismont opened this issue Mar 15, 2024 · 4 comments · May be fixed by #92
Open

Introduce a cache storage SPI #67

tsegismont opened this issue Mar 15, 2024 · 4 comments · May be fixed by #92
Labels
enhancement New feature or request gsoc2024

Comments

@tsegismont
Copy link
Contributor

When the cache is enabled, cached content is stored on heap memory.

Users should be able to choose between different storage implementations.

@wzy1935
Copy link
Contributor

wzy1935 commented Jul 9, 2024

For this one, my current thought is this:

  interface Cache {
    Future<Void> put(String key, String value);
    Future<String> get(String key);
    Future<Void> remove(String key);
    Future<Void> removeEldest();
    Future<Integer> size();
  }

Here I use String as the value, not Resource because I think it might be better if we do the en/decoding for the users.

Another thing I'm worrying about is whether the output parameter should be wrapped with Future. For example, vertx-redis-client uses async functions for its APIs.

@tsegismont
Copy link
Contributor Author

For this one, my current thought is this:

  interface Cache {
    Future<Void> put(String key, String value);
    Future<String> get(String key);
    Future<Void> remove(String key);
    Future<Void> removeEldest();
    Future<Integer> size();
  }

I think the removeEldest method isn't necessary in the interface. It's an implementation detail.

Here I use String as the value, not Resource because I think it might be better if we do the en/decoding for the users.

What do you mean with encoding/decoding? What would be the benefit?

Another thing I'm worrying about is whether the output parameter should be wrapped with Future. For example, vertx-redis-client uses async functions for its APIs.

Indeed, we should consider every operation on the cache may be asynchronous (not only for Redis, we could imagine an implementation with Infinispan, Hazelcast, ... etc).

@wzy1935
Copy link
Contributor

wzy1935 commented Jul 11, 2024

What do you mean with encoding/decoding? What would be the benefit?

The encoding/decoding refers to how to transform data between Resource objects to raw bytes in order to store them (serialization). If we do the serialization for the user (meaning that the parameter is either String or byte[]), the benefit would be that the SPI would be easier to implement for the user since storing bytes or strings is easy; If not (meaning that the parameter is Resource), the user would have more control on serialization, on the other hand. So that's a design option that I'm not sure.

@tsegismont
Copy link
Contributor Author

We don't have any other choice than caching the Resource object as value, do we? Because we need not only the cached response but all the metadata.

Regarding how to convert this to bytes or vert.x Buffer, take a look at Vert.x Web SessionStore SPI and the Sesssion implementation. In Vert.x core we have the ClusterSerializable that provides a contract for serializing to or deserializing from a Buffer.

@wzy1935 wzy1935 linked a pull request Jul 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gsoc2024
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants