Skip to main content

dox_cache 3.2.2 copy "dox_cache: ^3.2.2" to clipboard
dox_cache: ^3.2.2 copied to clipboard

Cache for Dart and the Dox framework. Memory, file and Redis drivers, TTL, locks, tags and remember helpers.

3.2.2 #

  • Fix: a user key could hit an internal key of the cache. forget('lock:report') freed the lock held by lock('report') on Redis and database stores. put('tag:dart', {...}) broke tags(['dart']).flush(). lock('remember:x') blocked remember('x', lock: true). Now a key, lock name or tag name that starts like an internal one gets a # in front before it goes to the driver. Internal keys do not change.
  • Upgrade note: user keys that start with lock:, tag:, flexible:created: or # are stored under a new name, so they miss the cache once after the upgrade. The same goes for lock names that start with remember:, flexible:, dox:auto-prune or #, and for tag names that start with # or with 40 hex digits and :. Nothing else changes.

3.2.1 #

  • New: a redis store takes 'options': RedisOptions(...). It is used as it is, so you can set commandTimeout, connectTimeout, onError and more.
  • options with host, port, username, password, db, tls or pool_size, or a value that is not a RedisOptions, throws an ArgumentError.
  • RedisOptions, RedisTimeoutError and RedisQueueFullError are exported. Old configs do not change.
  • Fix, disk: the file store never cleaned up by default, so expired files (like old sessions) stayed on the disk for ever. Now, with prune_every 0 (the default), a write starts a light prune in the background at most once an hour. It deletes expired files, temp files left by a crash, and free lock files. It keeps files it can not read or decrypt, so another app in the same folder keeps its files. It only touches files the cache made: other files in the folder stay. A lock file on disk makes sure only one runs per hour for all isolates and servers on one folder, also when the app restarts often. In a process, the first one can start on the first write that comes at least a minute after the first write of that process, so short commands never start one. Files that pull or a lock moved away for a moment and that a crash left behind are deleted after an hour, and flush() deletes moved values too. Expired files already read as a miss, so reads do not change.
  • FileDriver.prune() now also deletes temp files older than an hour and lock files that are free. Its result still counts only value files.
  • Fix: a value file with JSON that is not a map, or with an expiry time that is not a whole number, threw a TypeError on read. Now it reads as a miss, like other broken files.
  • Fix, disk: a write that failed (eg. a full disk) left its temp file. Now it is deleted.
  • New: fsync option on a file store (default true, as before). fsync: false skips the sync to disk on each write, so writes are faster. After a power cut the last writes can then be lost (they read as a miss).
  • Perf: lock files of the file store (add, increment, touch and lock()) are no longer synced to the disk. The sync did not make a lock survive a power cut anyway, because the folder was never synced. This halves the syncs of add and increment.
  • Perf: the memory store with max_size removed the least recently used item in O(n) time per write when full. Now each step is O(1).
  • Perf, memory: the memory store drops expired items at the front of the list on each write (at most two), not only in the sweep after 1000 or more writes.

3.2.0 #

  • New: dox cache:install [--store=file|redis|memory|database], run by dox add cache. It writes lib/config/cache.dart, the CACHE_STORE key and the AppEnv getters, and adds cache: cache to lib/config/app.dart. With --store=database it also adds dox_cache_database, its provider and the cache table migration. It never overwrites a file. dox_cache now depends on dox_annotation.
  • New: 'encrypt': true on a file or redis store encrypts the values. It is off by default, so nothing changes for stores without it. Set CacheConfig(encrypter: ...) with a CacheEncrypter. A store with 'encrypt': true and no encrypter throws a StateError, for every store type. Memory and null stores do not encrypt. An encrypt value that is not true or false throws an ArgumentError.
  • On Redis, a plain int stays plain text when encryption is on, so increment and decrement still work. Every other value is encrypted. To keep a secret number encrypted, store it as a String.
  • A value that cannot be decrypted (wrong key, changed text) reads as a miss. An old plain value reads as a miss too, except an int on Redis.
  • FileDriver.prune() deletes files that cannot be decrypted when encryption is on.
  • Cache keys and tag names are not encrypted, and a value is not tied to its key. Encryption protects against reading only. maxValueBytes is checked on the plain JSON size.
  • Ships an AI agent skill (dox-cache-guide). Install it in your app with dart run skills@ get.
  • New: CacheFlags, opt-in behaviors that work like Laravel, as CacheConfig(flags: ...). All are off by default. CacheFlags.all() turns on every flag.
  • New: CacheFlags.lockThrows makes lock.block(timeout) with no callback throw LockTimeoutException when the time is over, not give false.
  • New: CacheLock.throwOnTimeout picks this for one lock. A store sets it from the flag. CacheStore takes flags:.

3.1.3 #

  • Version bump only, to match the other packages.

3.1.2 #

  • Version bump only, to match the other packages.

3.1.1 #

  • New: flexible takes a null stale. Then the value is kept until a refresh replaces it, so callers still get the last good value when compute fails.

3.1.0 #

  • New: the file driver can delete expired and broken files by itself. Set the prune_every option (or FileDriver(pruneEvery: ...)) to run prune() in the background once every that many writes. It is off by default (0). Only one prune runs at a time, and a failed prune is ignored.
  • Fix: FileDriver.prune() could delete a new value that add, increment or touch wrote at the same time. Now it takes the same key lock as they do and reads the file again under it. A key that is locked right now is skipped.

3.0.2 #

  • Fix: remember and rememberForever threw on a cache hit when T was not a raw JSON type, like List<String>. Pass the new decode option to turn the cached JSON into T. Without it, T must be a raw JSON type.
  • Fix: remember runs compute once when many calls for the same key run at the same time in one isolate. The others wait for the first. With the new lock: true, callers in other isolates and servers wait too.
  • Fix: pull is atomic now. Redis uses GETDEL (needs Redis 6.2 or newer). Drivers get a new pull method.
  • Fix: the file driver keeps each prefix in its own sub folder. flush deletes only the files of its own prefix, and keeps temp files of writes that are running.
  • Change: because of this, files written by older versions are in the base folder and are not found any more. It is a cache, so they are only misses. You can delete the old files in the base folder by hand.
  • Fix: a file driver read no longer deletes an expired or broken file. Another isolate may have just written a new value. Use the new FileDriver.prune() to delete expired and broken files.
  • Fix: the file driver has locks now (File.create(exclusive: true)). add, increment and touch take a lock on the key, so they are safe across isolates.
  • Fix: a Redis prefix with no : at the end gets one. So the prefix app does not match the keys of app2.
  • New: flexible(key, fresh, stale, compute): stale while revalidate.
  • New: touch(key, ttl) sets a new ttl and keeps the value.
  • New: get and pull take a function as the default. It runs only on a miss.
  • New: lock.block(timeout, callback) runs the callback while it holds the lock. It throws LockTimeoutException when the time is over. lock.forceRelease() frees a lock of any owner.
  • New: the Redis option max_value_bytes.
  • Faster: tagged many, putMany, has, pull and remember read the tag versions once per call.
  • Faster: the memory driver keeps the expiry as int milliseconds. It does not read the clock for items with no expiry. has does not decode the value.
  • Change: MemoryEntry.expiresAt is an int in milliseconds now. CacheClock has a new nowMs().

3.0.1 #

  • Version bump only, to match the other packages.

3.0.0 #

  • The first stable release.

3.0.0-rc.1 #

  • Needs ioredis 3.0.1. It fixes a crash on disconnect when the Redis host is a name like localhost or redis.

3.0.0-alpha.17 #

  • Version bump only, to match the other packages.

3.0.0-alpha.16 #

  • Change: uses ioredis ^3.0.0, the first stable ioredis release.

3.0.0-alpha.15 #

  • Version bump only, to match the other packages.

3.0.0-alpha.14 #

  • Version bump only, to match the other packages.

3.0.0-alpha.13 #

  • Version bump only, to match the other packages.

3.0.0-alpha.12 #

  • Version bump only, to match the other packages.

3.0.0-alpha.11 #

  • Version bump only, to match the other packages.

3.0.0-alpha.10 #

  • Version bump only, to match the other packages.

3.0.0-alpha.9 #

  • Version bump only, to match the other packages.

3.0.0-alpha.8 #

  • Version bump only, to match the other packages.

3.0.0-alpha.7 #

  • Perf: the memory driver removes expired items and expired locks in a sweep after many writes. Before, a key that was written once with a ttl and never read again stayed in memory forever.
  • Perf: the memory driver with no max_size does not reorder the map on every hit. The order is only needed for LRU.
  • Perf: a tagged cache reads all tag versions with one many call (one MGET on Redis). tags(...).flush() raises all tag versions at the same time. Before, each tag was one round trip after the other.
  • Perf: the Redis driver frees a lock with EVALSHA. It sends the full script only when Redis does not know it yet.
  • Perf: the file driver makes the cache folder only when it is missing. Before, it ran create(recursive: true) on every write. Lock tokens use one shared Random.secure().

3.0.0-alpha.6 #

  • New CacheManager.close(). It closes the connections of every store that was built. The Redis driver closes its connection and its pool connections, with no reconnect. Memory, file and null stores do nothing. It is safe to call twice. A store used after it is built again.
  • New CacheDriver.close(), for one driver. Custom drivers can override it. The default does nothing.

3.0.0-alpha.5 #

  • Version bump only, to match the other packages.

3.0.0-alpha.4 #

  • Version bump only, to match the other packages.

3.0.0-alpha.3 #

  • New: getRaw(key) gives the stored value as JSON text, with no decode. Use it to send a cached value as a JSON response. Memory and Redis return the stored text as is. A stored String comes back with its quotes ("bar"). The stored format did not change, so old values still read the same.
  • Faster get: a plain store builds the key with no async step. itemKey now returns FutureOr<String>. Memory get costs about 0.6 µs instead of 0.86 µs. Memory getRaw costs about 0.3 µs.
  • New Redis option pool_size: the most connections one store opens (ioredis maxConnection). Default is 10, the same as before.
  • Uses ioredis 2.0.0-alpha.2. It sends all commands on one shared connection and writes them together (auto-pipelining). A Redis read costs much less CPU. The cache now uses one connection per store, so pool_size rarely matters.

3.0.0-alpha.2 #

  • Needs Dart 3.13 or newer.
  • All dependencies updated to their latest versions.

3.0.0-alpha.1 #

  • Uses ioredis 2. Redis error replies throw RedisError.
  • Redis: no value size limit by default (was 60 KB). maxValueBytes is still there if you want one.
  • Redis: many uses one MGET, putMany uses one pipeline, flush uses SCAN + DEL (no Lua).
  • First release.
  • CacheManager with named stores and custom drivers.
  • Drivers: memory (with LRU), file, Redis, null.
  • remember, pull, add, increment, many, tags and atomic locks.
0
likes
160
points
2.27k
downloads

Documentation

API reference

Publisher

verified publisherdartondox.dev

Weekly Downloads

Cache for Dart and the Dox framework. Memory, file and Redis drivers, TTL, locks, tags and remember helpers.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

crypto, dox_annotation, ioredis

More

Packages that depend on dox_cache