/** * Creates a file store for a cache. * * @param cache the cache */ @SuppressWarnings("unchecked") public PdoCacheFileStore(PdoCache<T> cache) { this.cache = cache; AbstractApplication application = AbstractApplication.getRunningApplication(); if (application != null) { Session session = application.getSession(); applicationName = StringHelper.toAsciiLetterOrDigit(application.getName()); backendName = StringHelper.toAsciiLetterOrDigit(session.getUrl()); } else { applicationName = null; backendName = null; } fileName = StringHelper.toAsciiLetterOrDigit(cache.getObjectClass().getName()) + CACHE_FILE_EXTENSION; }
/** * Verifies the cache data after being read from storage. */ private void verifyAfterRead() { String expectedApplicationName = null; String expectedBackendName = null; AbstractApplication application = AbstractApplication.getRunningApplication(); if (application != null) { expectedApplicationName = StringHelper.toAsciiLetterOrDigit(application.getName()); Session session = application.getSession(); if (session.isRemote()) { expectedBackendName = StringHelper.toAsciiLetterOrDigit(session.getUrl()); } } String expectedFileName = StringHelper.toAsciiLetterOrDigit(cache.getObjectClass().getName()) + CACHE_FILE_EXTENSION; if (!Objects.equals(expectedApplicationName, applicationName)) { throw new PdoRuntimeException("cache data belongs to application '" + applicationName + "', expected (running) application is '" + expectedApplicationName + "'"); } if (!Objects.equals(expectedBackendName, backendName)) { throw new PdoRuntimeException("cache data belongs to backend '" + backendName + "', expected (running) backend is '" + expectedBackendName + "'"); } if (!Objects.equals(expectedFileName, fileName)) { throw new PdoRuntimeException("cache data belongs to file '" + fileName + "', expected filename is '" + expectedFileName + "'"); } }