Differences from Spring
spring_boot_starter_cache follows Spring's cache abstraction and Spring Boot's auto-configuration: the same annotations, SpEL variables, interfaces and properties. This page lists where it does not, and why.
Why
The differences come from Dart (no reflection, no overloading, collections that compare by identity, Future and Stream) and from a built-in store with expiry and size limits, so most applications need no extra library.
Example
@Cacheable.of(cacheNames: ['books', 'isbn'], key: '#isbn')
Future<Book> find(String isbn) => api.load(isbn);
@Cacheable(cacheNames = {"books", "isbn"}, key = "#isbn")
public Book find(String isbn) { ... }
Differences
| Spring | Here | Why |
|---|---|---|
@EnableCaching |
not needed; spring.cache.type=none turns caching off |
The starter is enough. |
@Cacheable({"a", "b"}) |
@Cacheable('a'), or @Cacheable.of(cacheNames: [...]) |
A Dart constructor cannot mix an optional positional parameter with named ones. |
#root.caches are Cache objects, #root.targetClass a Class, #root.method a Method |
cache names, the class name, a MethodSignature (as text) |
No reflection. |
CacheManagerCustomizer<T> |
not generic; the customizer checks the manager's type | The container finds beans by their exact type. |
CompletableFuture cached by value (6.1) |
Future cached by value |
|
sync waits per method |
per cache and key: two sync methods with the same cache and key share one pending result |
|
The cache does the waiting of sync (Cache.get(key, Callable)) |
the interceptor keeps the running calls, by the cache's name and the key. A cache that stores under another key than the one it is asked with (one that adds the caller or a tenant) implements KeyScopingCache; its storedKey(key) is then what the calls are shared by |
Cache has no value loader. Without KeyScopingCache, callers the cache keeps apart would share one answer. The interface is this starter's own. |
ConcurrentMapCacheManager without expiry or size; Caffeine for those |
the in-memory caches have a time to live and a size limit (spring.cache.simple.*) |
So a long-running server does not grow without bound. |
spring.cache.type with many stores |
generic, simple, disk, none; disk keeps the entries on disk, so they outlive a restart (Caches that outlive a restart), and is this starter's own |
No Caffeine, Redis or JCache yet. |
SimpleKeyGenerator wraps only arrays |
it also wraps a single list, set or map in a SimpleKey |
Dart collections compare by identity; the key compares by content. |
A Flux is collected and replayed (6.1) |
@Cacheable / @CachePut on a Stream method fail the build |
A generic interceptor cannot create a Stream<T> of the right type without reflection. |
Cache with get(key, Class), get(key, Callable), retrieve, getNativeCache |
name, get, put, putIfAbsent, evict, evictIfPresent, clear, invalidate; retrieve on AsyncCache, a cache whose store answers later (the caches on disk) |
|
invalidate() tells whether entries were removed |
CacheDefaults always returns true; InMemoryCache counts expired entries not yet swept |
|
CachingConfigurer methods may be @Bean |
must not be: they are called once | No @Configuration proxies in Dart. |
CacheErrorHandler gets the exception |
it also gets the stack trace | |
The sync rules checked at the first call |
all annotation rules checked when the bean is created | Fail at startup. |
Not supported yet
- Caffeine, Redis, JCache and Hazelcast cache types.
- A value loader (
get(key, Callable)). - Caching
Streamresults.