MCPcopy Create free account
hub / github.com/BaseXdb/basex / cache

Method cache

basex-core/src/main/java/org/basex/core/cmd/Add.java:142–163  ·  view source on GitHub ↗

Decides if the input should be cached before being written to the final database. @param parser parser reference @return result of check

(final Parser parser)

Source from the content-addressed store, hash-verified

140 * @return result of check
141 */
142 private boolean cache(final Parser parser) {
143 // main memory mode: never write to disk
144 if(options.get(MainOptions.MAINMEM)) return false;
145 // explicit caching
146 if(options.get(MainOptions.ADDCACHE)) return true;
147
148 // create disk instances for large documents
149 // (does not work for input streams and directories)
150 final IO source = parser.source();
151 long fl = source.length();
152 if(source instanceof final IOFile src && src.isDir()) {
153 for(final String path : src.descendants()) fl += new IOFile(src, path).length();
154 }
155
156 // check free memory
157 final Runtime rt = Runtime.getRuntime();
158 final long max = rt.maxMemory();
159 if(fl < (max - rt.freeMemory()) / 2) return false;
160 // if caching may be necessary, run garbage collection and try again
161 Performance.gc(2);
162 return fl > (max - rt.freeMemory()) / 2;
163 }
164
165 @Override
166 public void build(final CmdBuilder cb) {

Callers 1

buildMethod · 0.95

Calls 5

lengthMethod · 0.95
gcMethod · 0.95
getMethod · 0.65
isDirMethod · 0.45
descendantsMethod · 0.45

Tested by

no test coverage detected