Repository navigation
What's New
-
Block-level read cache: an
SMB.Connectioncan keep what it reads, so reading the same bytes again doesn't go over the network. Attach a cache and nothing else in your code changes. Files you open, uploads and downloads, streams,compareFiles, and the AVFoundation and EXIFKit integrations all read through it.let cache = SMB.ReferenceCache(configuration: .init()) connection.attachCache(cache)
fork()passes the cache on to the new connection, anddisconnect()detaches it. Files that are already open keep their cache until they close.detachCache()andhasCacheAttached()complete the API.- The connection reports every change it makes to the cache: writes, appends, moves, deletes, truncations, date, attribute and security changes, links, copies, and opens with
.createor.truncate. The cache then drops the bytes, stats and listings those changes make stale. - A cache never makes an operation fail. When it has nothing to offer, or runs into trouble, the connection reads from the server.
- Attaching a cache adds one extra stat round trip per file opened for reading, and one before closing a file that was written. Without a cache, there is no extra cost.
-
SMB.ReferenceCache: a ready-to-use cache with these options:- Storage: bytes are kept in an
SMB.CacheStorage. The defaultSMB.InMemoryCacheStoragehas a byte budget (256 MiB by default) and an optionalmaximumFileSize. It evicts the least recently used files and gives memory back under memory pressure. Several caches can share one storage and its budget. - Trust policies: with
.statOnServer(size, last-write time and change time) or.sampleBlocks(count:scan:), the cache notices changes made by other clients. These checks run through a control connection that you open, usually withtry await connection.fork(), and close yourself. - Metadata policy: decides whether
stat(at:),itemExists(at:)andlistDirectory(at:)may be answered from the cache, and for how long. pathMatching: controls how share paths are matched..exactis the default;.caseInsensitivelets case variants share an entry on case-insensitive shares. Either way, a change drops every spelling that may name the same file, including spellings that differ in case or Unicode normalization.
- Storage: bytes are kept in an
-
Custom caches: implement
SMB.BlockLevelReadCacheto plug in your own cache, orSMB.CacheStorageto keepReferenceCache's bookkeeping and store the bytes elsewhere.
See the new Block-Level Cache guide.