Skip to content

Add support for caching level - #227

Merged
3lvis merged 2 commits into
masterfrom
support-for-disabling-caching
Feb 11, 2018
Merged

Add support for caching level#227
3lvis merged 2 commits into
masterfrom
support-for-disabling-caching

Conversation

@3lvis

@3lvis3lvis commented Feb 11, 2018

Copy link
Copy Markdown
Owner

Allows the user to disable caching per request.

networking.downloadImage("/image/png", cachingLevel:.none){ result in
// Non-cached image....
}

@3lvis
3lvis merged commit 87d477c into masterFeb 11, 2018
@3lvis
3lvis deleted the support-for-disabling-caching branch February 11, 2018 08:38
@3lvis3lvis mentioned this pull request Feb 11, 2018
3lvis added a commit that referenced this pull request Jun 18, 2026
* Drop dead AnyCodable.encode(to:)
AnyCodable conforms only to Decodable, so encode(to:) satisfied no
protocol and had no callers. It was also incomplete (threw on the
nested AnyCodable collections that init(from:) produces).
* Fix download orphan cache write and empty Data verb body
- requestData wrote the payload under the path-derived key, then the
download handlers wrote it again under the real cacheName. With a
cacheName that left a stray file no read path uses; with none it was a
redundant double write. Caching is now the handlers' job only; drop
requestData's now-dead cachingLevel parameter.
- A verb with T == Data returned an empty Data on success instead of the
response body. Return the actual body (the Void overloads discard it,
so they're unaffected).
* Fix .memory cache read destroying the disk tier
objectFromCache's .memory branch deleted the on-disk file on every read
(present since the 2018 caching feature, #227). With the warm/cold
tiering, that file is the durable cold copy of an earlier .memoryAndFile
write — so a .memory read evicted it, and once the warm NSCache tier was
dropped under pressure the entry was lost entirely, forcing a re-fetch.
Make .memory a pure read of the warm tier; purging stays the write
path's and clearCache's job.
* Make .none cache read pure too — no purge on read
objectFromCache's .none branch purged both tiers on read. The verb path
already guards against calling it for .none, but the download path reads
through it unconditionally, so a .none download wiped a disk entry an
earlier .memoryAndFile write had created. Report a miss without touching
either tier; clearCache is the way to evict. objectFromCache is now a
pure read at every level.
* Extract the disk-cache subsystem into CacheStore
The two-tier cache (warm NSCache over the sharded on-disk layout), its
TTL/expiry, sweep, and clear were scattered across static and instance
members on the Networking actor. Move them into a dedicated CacheStore —
a non-actor @unchecked Sendable keyed by a resolved resource string, so
the layout/sharding/sweep logic is cohesive and independently testable.
Networking keeps the public surface unchanged: destinationURL,
objectFromCache, cacheOrPurgeData/Image are thin nonisolated shims that
resolve the cache key (baseURL + path stays the networking layer's job,
via cacheResource) and delegate. The injected NSCache is shared by
reference so it stays inspectable. Behavior-preserving — full suite green.
* Audit comments added in this PR
Cut DI-narration on folderName, a duplicated baseURL-agnostic note on
cacheResource, the regression-test file header (duplicated the per-test
comments), and two test comments that restated the test name/assertion.
Comment-only; full suite green.
* Test CacheStore directly; decouple cache tests from the actor
The cache-layout, sliding-TTL expiry, pure-read, and clear behaviors are
the store's, but were tested through Networking's internal shims
(objectFromCache/cacheOrPurgeData) — coupling the tests to actor
internals. Move them to CacheStoreTests against CacheStore directly.
Bonus: the .memory/.none pure-read contracts now run as deterministic
unit tests with real NSCache eviction (cache.removeAllObjects), which the
download-based versions couldn't do — and they need no go-httpbin.
destinationURL/CacheExpiry tests stay on Networking (public API / own
type). The internal shims keep their production callers (5/3/2 sites each
+ the path→resource resolution), so they remain — but no test depends on
them now.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@3lvis