When caching the DB method, the file data is not written, although as I understand it should. Tell me what's the reason

Configuration file

<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true"> <diskStore path="D:\"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="100" timeToLiveSeconds="180" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="true" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> <cache name="contacts" maxElementsInMemory="10000000" eternal="false" clearOnFlush="true" overflowToDisk="true" diskPersistent="true" diskExpiryThreadIntervalSeconds="10" timeToIdleSeconds="100" timeToLiveSeconds="180" memoryStoreEvictionPolicy="LFU"> </cache> </ehcache> 

Service

  @Override public List<Contact> regExFilterContacts(String filter) { Pattern pattern = Pattern.compile(filter); Matcher matcher; List<Contact> allContacts = getAllContacts(); if (filter.equals("") || filter.equals(null)) { return allContacts; } logger.info("Start filtering..."); List<Contact> filterListContact = new ArrayList<Contact>(); for (Contact oneContact : allContacts) { matcher = pattern.matcher(oneContact.getName()); if (!matcher.find()) { filterListContact.add(oneContact); } } return filterListContact; } } 

Controller

 @RestController public class MainController { public static final Logger log = Logger.getLogger(MainController.class.getName()); @Autowired private ContactService contactService; @RequestMapping(value = "/hello/contacts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Collection<Contact>> getContacts(@RequestParam(value = "nameFilter", defaultValue = "") String name) { log.info("Filter String is " + name); List<Contact> filterContacts = contactService.regExFilterContacts(name); Integer filterContactSize = filterContacts.size(); if (filterContactSize.equals(0)) { log.info("For you query contacts not found"); return new ResponseEntity<Collection<Contact>>(HttpStatus.NOT_FOUND); } return new ResponseEntity<Collection<Contact>>(filterContacts, HttpStatus.OK); } } 

thanks in advance

  • and where are you trying to write to the file? I can't see anything - Senior Pomidor
  • @TsovakSaakyan, as I understand it, when I call the getAllContacts method, the file is being written to. The call takes place in the controller that I added. - Dmitriy Smirnov
  • As far as I understand, to write to the file, you must first add maxElementsInMemory + 1 elements to the cache - Russtam
  • @Russtam did not quite understand what you mean. - Dmitriy Smirnov
  • You said that ehCache does not write data to the file, and brought the config (now it has disappeared somewhere). I told you that ehCache will drop data into the file only when the items in the cache are maxElementsInMemory + 1. Or specify the question. - Russtam

0