cacheman 0.7.3
cacheman: ^0.7.3 copied to clipboard
A small type-safe wrapper over get_storage with one API: TTL and absolute expiry, sliding renewal, namespaces, pluggable serialization and a key-bound helper.
0.7.3 #
- Shorten the pubspec description to meet the pub.dev length limit.
0.7.2 #
- Docs only: rewrote README wording in plain language.
0.7.1 #
- Docs only: README install snippet and migration chapter now describe the released 0.7.0 API (
Cacheman.custom,AsyncCacheman, subclass changes); example app gains aCacheman.customdemo and a real README; removed stale "planned" wording.
0.7.0 #
Highlights: layered storage (synchronous Cacheman + abstract AsyncCacheman, Cacheman.custom
for custom synchronous backends), structured CachemanError reporting, ValueAdapter, a
non-throwing read, narrowed force, and the shared Hub with watch/flush/flushDelay/
purgeOnInit. See the Breaking list and the README migration chapter before upgrading from 0.6.
Fixes (full review):
- Default listenRaw no longer throws StateError during get_storage initialization; table replacements notify all watchers and empty-string key writes no longer report clear.
- Sliding renewal requires createdAt, preserving foreign expireAt/ttl-shaped data.
- Jsonx DateTime stores epoch microseconds and UTC/local mode for timezone-safe round trips; legacy string data remains readable.
- Jsonx preserves NoSuchMethodError from toJson as JsonUnsupportedObjectError.cause; correct Enum documentation to explain encoding errors and explicit conversion.
Breaking:
onErroralways receives aCachemanErrorsubclass; inspectcausefor the original exception. Migrateerror is FormatExceptiontoerror is CorruptEntryError && error.cause is FormatException.read<T>type mismatches now return the default and reportTypeMismatchError, retaining data. Replace TypeError catches with onError handling; use ValueAdapter for typed collections or custom classes. int/double are not coerced; use num or an adapter.forceremains supported and defaults to true, but only retries backend write failures. Encoding/serialization/adapter failures report SerializeError without purge/retry; fix the converter instead of relying on repeated serialization. Final backend failures are WriteError; background persistence failures are FlushError; watch callback failures are WatchError.- Removed unused deprecated
CacheOptions; pass ttl/expireAt directly to write/writeAll. - Deprecated O(index)
key(index); replace repeated indexed calls with one keys() snapshot.
Added (stage 2):
- Source-compatible read(key, [default]) plus readWith(key, {defaultValue, adapter}); Dart cannot mix optional positional and named parameters in one signature.
- Shared typed value checks and ValueAdapter with eager listOf/mapOf conversion; typed fast/lazy/batchFast accessors support adapters and a default millisecond ttl.
Added (stage 1b):
- Private per-identity Hub with one backend listener, self-healing owned-key indexes, typed synchronous watch/cancel, own-write suppression and namespace migration.
- Opt-in flushDelay (shared earliest deadline), void flush(), pending-write lifecycle saves and nonblocking purgeOnInit. Defaults preserve existing persistence behavior.
Cacheman.custom(...)constructor for subclasses that bring their own primitives; plain forwarding subclasses keep full get_storage behavior (shared Hub, watch, flushDelay).- Protected notification/deferred-flush/identity hooks with conservative defaults for custom subclasses; lazy memoized CacheContext.key plus actual storageKey.
- Bilingual examples/docs and full acceptance matrix, zero-dependency coverage and test-name gates; regression coverage for stages 0/1a and legacy functionality.
Added (stage 1a):
- Protected synchronous storage primitives and CacheContext/CacheOp for user subclasses; the default GetStorage container is lazy and still receives the supplied path on first use.
- Abstract AsyncCacheman with awaited CRUD, TTL/absolute/sliding expiry, namespace/enckey, codecs, raw/readonly/force, ownership-aware enumeration and scoped erase. No built-in asynchronous backend or extra dependency; no read-value or owned-key set cache.
- Private composed core shared by both facades for key spaces, envelopes, validation, renewal decisions and original-error reporting. Existing synchronous APIs stay intact.
- Bilingual layered-storage docs with app-side SharedPreferencesWithCache, Hive CE LazyBox and dart:io examples, an interactive parallel-cache demo and primitive/async regression tests.
- Document preserved enckey-only erase protection, sync versus awaited force failures, backend lifecycle/concurrency boundaries and lazy container first-access path precedence.
Fixes:
- R1: Guard incremental owned-key updates with index identity and scope generation during reentrant namespace changes. / 重入切域时校验索引身份与作用域代数,防止跨域误删。
- R2: Use lowercase UTF-8 hex filenames in both directory-backend examples to avoid case-insensitive filesystem collisions. / 双语目录后端示例改用小写 UTF-8 十六进制,避免大小写碰撞。
- R3: Track onError exceptions by identity instead of a shared failure counter, so caught unrelated errors cannot interrupt watch dispatch. / 按异常身份识别 onError 传播,避免已处理的无关异常打断 watch。
- R4: Preserve handler exceptions and stacks through mutation Futures and Zone propagation instead of wrapping them as FlushError. / 变更 Future 中的处理器异常保留身份和堆栈,按 Zone 传播。
- R5: Skip migrated watchers in keyed notification snapshots while retaining clear delivery. / 键通知快照跳过已迁移 watcher,clear 仍通知所有活跃订阅。
- R6: Register delayed flush before memory notifications so reentrant writers retain latest error ownership. / 延迟落盘在内存通知前登记,保留重入写入者的最新错误归属。
- Align architecture, bilingual READMEs and contributor skill with the actual synchronous API,
sliding renewal after at least 10% of TTL elapsed, and get_storage's transitive
getdependency; remove the obsolete architecture SVG and correct example verification paths. - Guard the GetX interop example against collection/object feedback loops; document synchronous listeners, whole-container erase notifications and isolate-local storage maps.
- Cache decoded logical keys for
enckeyenumeration (bounded to 1024 entries); invalidate key caches on namespace changes. - Report read-time decode/deserialization failures via
onErroror print while still deleting unreadable entries and returning the default value; keep purge scans quiet. - Assert initialization before persistence in debug builds; release behavior is unchanged.
- Raise the Flutter minimum to 3.24.0 to match the Dart 3.5 SDK constraint.
Performance:
On-device profile benchmark against 0.6.0 (Android 12, arm64 profile build, real get_storage, shared API only; medians of 7 rounds, 3 alternating launches per version). Hot paths are at parity; the shared Hub, type checks and structured errors cost well under 1 µs per call. / 真机 profile 基准(对比 0.6.0):热路径持平,Hub、类型校验与结构化错误的单次开销远低于 1 µs。
| Case | 0.6.0 | 0.7.0 | new/old |
|---|---|---|---|
| read short string | 2.59 µs | 2.68 µs | 1.04 |
| read 1KB / 10KB map | 40.0 / 344.6 µs | 40.2 / 343.1 µs | 1.00 |
| read 1KB with ttl / sliding | 41.2 / 41.6 µs | 41.2 / 41.4 µs | 1.00 |
| write short string / 1KB map | 9.2 / 70.4 µs | 9.8 / 71.0 µs | 1.07 / 1.01 |
| writeAll / readAll 100 × 1KB | 6.78 / 3.69 ms | 6.94 / 3.71 ms | 1.02 / 1.01 |
| purge 2000 live entries | 8.06 ms | 6.80 ms | 0.84 |
| remove + write cycle | 13.6 µs | 18.8 µs | 1.38 |
| enckey write / read | 9.2 / 5.8 µs | 10.0 / 6.4 µs | 1.09 |
- The remove + write cycle pays about 5 µs for Hub version tracking and watch notification
(noisy: best runs differ by 0.6 µs); cached
lengthmoves from 0.03 to 0.2 µs for the Hub version check. First-timekeys()scans varied 2.5–6.7 ms within each version, so no difference is claimed.
0.6.0 #
Breaking:
- Namespace prefix is now unambiguous:
%and:inside a namespace are escaped (%25/%3A), sonamespace: 'a'+ keyb:xno longer collides withnamespace: 'a:b'+ keyx, anda.erase()no longer wipesa:b's data. Namespaces without%/:keep the same storage keys; for the rest, persisted entries under the old prefix are no longer visible (migrate or let them expire).Cacheman.namespacereturns the escaped prefix.
Fixes:
write()/ sliding renewal: a throwingserialize/codec is now inside_persist's try/catch, so it goes throughforce+onErrorinstead of escaping.purge()skipsrawmode (no envelope, no expiry);readonlychecks real presence (a storednullcounts, no sliding renewal side effect).Jsonx: falls back totoJson()for custom objects; a plainMapshaped like a type tag is escaped and round-trips unchanged.- Docs: get_storage 2.1.1's write Future cannot carry flush errors, so
onErroris only guaranteed for synchronous failures; same-container instances share the first-seenpath.
Added / deprecated:
CachemanOptions.keyCodec— a deterministic codec forenckey, independent of the valuecodec(falls back tocodec).CacheOptionsis@Deprecated(no method ever accepted it); removed in the next breaking release.- Internal:
length/key/keysread the owned-key set directly; erase reuses_del.
0.5.0 #
Breaking:
-
Removed
Cacheman.create().Cachemannow has a plain, synchronous constructor (Cacheman({container, path, options})) plus an instance methodensureInitialized()that must be called and awaited once before any read/write — the onlyFutureboundary in the API, same rolecreate()used to play. This lets external codeextend Cachemanand forward constructor params viasuper(...)without any factory boilerplate (Dart constructors can't beasync, which is whycreate()— a static factory — couldn't be subclassed cleanly).Migration:
final cache = await Cacheman.create(options: opts);→final cache = Cacheman(options: opts); await cache.ensureInitialized();
0.4.0 #
- Added
Cacheman.container— exposes the underlyingget_storageGetStorageinstance, for interop that needs the raw container (e.g.listenKeyfor external change notifications, such as wiring up a GetXRxfor reactive reads). - Added
Cacheman.storageKey(key)— returns the actual keykeyis persisted under (namespace-prefixed, andenckey-encoded when enabled). Needed alongsidecontainersince the real storage key is otherwise opaque onceenckey's pluggable codec is involved.
0.3.0 #
Breaking:
- Removed the
StoreandMemoCacheabstraction layers.Enginenow talks directly to aGetStoragecontainer and a plainMapread cache instead of going through an injected backend/memo-cache interface — both only ever had one real implementation (GetStorageAdapter/Memo), so the seam was pure indirection.GetStorageAdapterandMemo(and their fileslib/src/get_storage_adapter.dart/lib/src/memo.dart) are deleted.Store/MemoCache/Memowere previously part of the public export surface (package:cacheman/cacheman.dart) — any code importing them directly will no longer compile. This is an internal simplification with no behavioral change toCacheman's public API (read/write/remove/erase/... are unaffected). - Removed the in-process memo read-cache layer entirely. Every
readnow goes straight toget_storage; everywritepersists straight toget_storage, with no intermediate cache.CachemanOptions.memoized,CacheOptions.memoized,CachemanOptions.cloned, andCachemanOptions.deepClonedare all removed (there is no longer a shared memo reference forcloned/deepClonedto protect against — everyread()already returns a value freshly deserialized from JSON, never aliased to anything the engine holds onto).Engine.destroy()andCacheman.destroy()are removed — with no memo cache,destroy()had nothing left to do. - Merged the
Engineclass directly intoCacheman—Cachemanwas already a pure forwarding wrapper aroundEnginewith no other consumers, so the two are now one class (lib/src/cacheman.dart);lib/src/engine.dartis deleted, andCacheOptions/CachemanOptionsmoved tolib/src/options.dart. This is an internal simplification with no behavioral change toCacheman's public API, but it is breaking for anyone who imported theEnginetype directly (it was previously exported frompackage:cacheman/cacheman.dart) — that export is removed, since nothing outside the package ever constructed anEngineon its own.
0.2.0 #
Breaking:
ssin-memory tier removed; only the persistentlstier remains.Cacheman.create()no longer accepts acapparameter, andCacheman.ss/Memoryno longer exist.Engine's core CRUD methods renamed:get/getAll→read/readAll,set/setAll→write/writeAll,clear→erase.remove/removeAllare unchanged.Cacheman.lsremoved.Cachemannow exposesEngine's whole public API directly at the top level (read/readAll,write/writeAll,remove/removeAll,erase,key/keys/length/purge/namespace) — callcache.write(...)/cache.read(...)etc. instead ofcache.ls.write(...)/cache.ls.read(...).fast/lazy/batchFast/debug()now take aCachemaninstead of anEngine(fast<String>(cache, 'token'),debug(cache)).
0.1.0 #
Initial version — a get_storage-backed persistent tier (ls) plus a pure in-memory tier (ss),
sharing one engine: TTL & absolute expiry, sliding renewal, namespaces, pluggable serialization, an
optional Codec hook (no implementation shipped), batch get/set/remove, raw/readonly modes,
fast/lazy/batchFast key-bound accessors, a debug() snapshot helper, an optional ss capacity cap
(cap, FIFO eviction), and a generic Jsonx serializer round-tripping DateTime/Duration/Set/
BigInt/Uri/RegExp. The Dart/Flutter sibling of @codejoo/storage.