Skip to content

Commit

Permalink
document cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Feb 5, 2024
1 parent 332914e commit b9a4974
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/cached.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ function _readblock_cached(A, data, I...)
return data
end

function cached(A::AbstractArray)
isdiskarray(A) || throw(ArgumentError("Array `$(typeof(A))` is not a disk array"))
CachedDiskArray(A)
end
"""
cache(A::AbstractArray; maxsize=1000)
Wrap internal disk arrays with `CacheDiskArray`.
This function is intended to be extended by package that want to
re-wrap the disk array afterwards, such as YAXArrays.jl or Rasters.jl.
"""
cache(A::AbstractArray; maxsize=1000) = CachedDiskArray(A; maxsize)
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,10 @@ end
# Read from the cache
@test ca[:, :] == ch
length(ca.cache)

ca = DiskArrays.cache(ch; maxsize=5)
@test sum(ca) == sum(ca)
# Read from the cache
@test ca[:, :] == ch
length(ca.cache)
end

0 comments on commit b9a4974

Please sign in to comment.