Skip to content

Best Practice 3 - Cache: Local and remote strategy. #196

@barbara79

Description

@barbara79

Commercetools resources are versioned, so it is possible to cache resources, since in case the cache is outdated we get a version conflict from the platform and all we have to do is invalidate the outdated cache entry.

We can use both cache strategies, either local, or remote (redis or other cach providers). but at the same time we dont want to bind ourselves to a specific provider, this is why we can create a cache interface that we use in a middleware. and which abstract the cache (local and remote ) away.

maybe use javax.persistence.Cache, or create an interface similar to

public interface CtpCache {
     Future<Object> upsert(String key, Object object);
     Future<Object> get(String key);
     void invalidate(String key);
}

public class CacheMiddleware {
        public CacheMiddleware(CtpCache cache){
        .....
        }
} 

linked to #192

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions