Skip to content

Commit f72f9b6

Browse files
committed
FEAT: thru-cache module updated to version 0.2.0 (exists-thru?, list-thru) + bugfix
1 parent d9e52c6 commit f72f9b6

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

src/modules/thru-cache.reb

+34-16
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ Rebol [
44
name: thru-cache
55
type: module
66
options: [delay]
7-
version: 0.1.0
8-
exports: [path-thru read-thru load-thru do-thru clear-thru]
7+
version: 0.2.0
8+
exports: [path-thru read-thru load-thru do-thru clear-thru list-thru exists-thru?]
99
author: @Oldes
1010
file: %thru-cache.reb
1111
home: https://src.rebol.tech/modules/thru-cache.reb
1212
]
1313

14+
;; Initialize the directory for storing local files
15+
so: system/options
16+
unless select so 'thru-cache [
17+
put so 'thru-cache join to-real-file any [
18+
get-env "TEMP"
19+
so/data
20+
] %thru-cache/
21+
sys/log/info 'REBOL ["Using thru-cache:" mold so/thru-cache]
22+
]
23+
1424
path-thru: func [
1525
{Returns the local disk cache path of a remote file}
1626
url [url!] "Remote file address"
1727
return: [file!]
18-
/local so hash file path
28+
/local hash file path
1929
][
20-
so: system/options
21-
unless select so 'thru-cache [
22-
put so 'thru-cache join to-real-file any [
23-
get-env "TEMP"
24-
so/data
25-
] %thru-cache/
26-
sys/log/info 'REBOL ["Using thru-cache:" mold so/thru-cache]
27-
]
30+
unless find so 'thru-cache [return none]
2831
hash: checksum form url 'MD5
2932
file: head (remove back tail remove remove (form hash))
3033
path: dirize append copy so/thru-cache copy/part file 2
@@ -83,19 +86,19 @@ do-thru: func [
8386

8487
clear-thru: func [
8588
"Removes local disk cache files"
86-
/only filter [string!] "Delete only files where the filter is found"
89+
/only filter [string!] "Delete only the files that match the filter"
8790
/test "Only print files to be deleted"
8891
/local temp dir log
8992
][
90-
unless exists? dir: select system/options 'thru-cache [exit]
93+
unless exists? dir: select so 'thru-cache [exit]
9194
log: dir/read-thru.log
9295
if test [
9396
unless exists? log [exit]
9497
filter: any [filter "*"]
9598
foreach [path url] transcode read log [
9699
if all [
97100
exists? dir/:path
98-
find/any url filter
101+
find/any/match url filter
99102
][ print [as-green skip path 3 url] ]
100103
]
101104
exit
@@ -118,8 +121,23 @@ clear-thru: func [
118121
()
119122
]
120123

124+
exists-thru?: func[
125+
"Returns true if the remote file is present in the local disk cache"
126+
url [url! file!] "Remote file address"
127+
][
128+
exists? any [all [file? url url] path-thru url]
129+
]
130+
131+
list-thru: func[
132+
"Prints localy stored URLs"
133+
/only filter [string!] "List only the files that match the filter"
134+
][
135+
sys/log/info 'REBOL ["Used thru-cache directory:" mold so/thru-cache]
136+
clear-thru/:only/test filter
137+
]
138+
121139
log-thru-file: func[path url][
122-
write/append system/options/thru-cache/read-thru.log ajoin [
123-
#"%" copy/part tail path -32 SP url LF
140+
write/append so/thru-cache/read-thru.log ajoin [
141+
#"%" copy/part tail path -32 SP mold url LF
124142
]
125143
]

0 commit comments

Comments
 (0)