Skip to content

Commit

Permalink
MGR-150
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Müller authored and Matthias Müller committed Apr 5, 2023
1 parent 73ecb9b commit fa1bf07
Show file tree
Hide file tree
Showing 8 changed files with 472 additions and 67 deletions.
2 changes: 1 addition & 1 deletion application-home/conf/datasources/ds-cache.xml
Expand Up @@ -46,7 +46,7 @@
<param name="clearLink" />
</params>
<meta-data bindClass="org.appng.application.manager.business.Cache$CacheEntry">
<field name="id" type="text" displayLength="75">
<field name="id" type="text" displayLength="150">
<sort />
<label>id</label>
</field>
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/appng/application/manager/business/Cache.java
Expand Up @@ -130,12 +130,12 @@ public Page<CacheEntry> getCacheEntries(Request request, FieldProcessor fp, Opti
javax.cache.Cache<String, CachedResponse> cache = CacheService.getCache(cacheSite.get());
if (null != cache) {
cacheSize = cache.unwrap(ICache.class).size();
int idx = 0;
int startIdx = pageable.getOffset();
int endIdx = pageable.getOffset() + pageable.getPageSize();

if (cacheSize > maxCacheEntries) {
Iterator<javax.cache.Cache.Entry<String, CachedResponse>> elements = cache.iterator();
int idx = 0;
int startIdx = pageable.getOffset();
int endIdx = pageable.getOffset() + pageable.getPageSize();
while (elements.hasNext()) {
javax.cache.Cache.Entry<java.lang.String, CachedResponse> entry = elements.next();
CachedResponse cachedResponse = entry.getValue();
Expand Down Expand Up @@ -175,9 +175,12 @@ public Page<CacheEntry> getCacheEntries(Request request, FieldProcessor fp, Opti
entryId.substring(entryId.indexOf('/')), entryName, IOCase.INSENSITIVE);
boolean typeMatches = !filterType || FilenameUtils
.wildcardMatch(cachedResponse.getContentType(), entryType, IOCase.INSENSITIVE);
if (nameMatches && typeMatches) {
if (nameMatches && typeMatches && idx >= startIdx && idx < endIdx) {
cacheEntries.add(new CacheEntry(cachedResponse));
}
if (idx++ >= endIdx) {
break;
}
}
}

Expand Down
Expand Up @@ -116,13 +116,13 @@ protected Properties getProperties() {
properties.put("platform.platformRootPath", "target/ROOT");
properties.put("site.mailHost", "localHost");
properties.put("site.mailPort", "25");
properties.put(ManagerSettings.MAX_FILTERABLE_CACHE_ENTRIES, "50");
properties.put(ManagerSettings.MAX_FILTERABLE_CACHE_ENTRIES, "600");
return properties;
}

@Override
protected List<Property> getPlatformProperties(String prefix) {
List<Property> platformProperties = super.getPlatformProperties(prefix);
List<Property> platformProperties = super.getPlatformProperties();
SimpleProperty templates = new SimpleProperty(prefix + Platform.Property.TEMPLATE_FOLDER, "templates");
platformProperties.add(templates);
return platformProperties;
Expand Down
Expand Up @@ -19,6 +19,7 @@

import javax.cache.Cache;

import org.appng.api.ProcessingException;
import org.appng.api.support.CallableDataSource;
import org.appng.core.controller.CachedResponse;
import org.appng.core.service.CacheService;
Expand Down Expand Up @@ -50,24 +51,42 @@ public class CacheTest extends AbstractTest {
@Test
public void testCache() throws Exception {
Cache<String, CachedResponse> cache = CacheService.createCache(site);
fillCache(cache, 0, 500);
Datasource datasource = getCacheDataSource();
validate(datasource, new DateFieldDifferenceHandler());
}

@Test
public void testCacheNoFilter() throws Exception {
Cache<String, CachedResponse> cache = CacheService.getCache(site);
fillCache(cache, 500, 700);
Datasource datasource = getCacheDataSource();
validate(datasource, new DateFieldDifferenceHandler());

for (int i = 0; i < 500; i++) {
}

private void fillCache(Cache<String, CachedResponse> cache, int start, int end) {
for (int i = start; i < end; i++) {
String key = "/element/" + i;
cache.put(key, new CachedResponse(key, site, servletRequest, 200, MediaType.TEXT_PLAIN_VALUE, new byte[0],
null, 3600));
}
}

public Datasource getCacheDataSource() throws ProcessingException {
addParameter("sortCacheElements", "pageSize:10;page:4");
initParameters();
CallableDataSource ds = getDataSource("cacheElements").withParam("siteid", "1").getCallableDataSource();
ds.perform("");

Datasource datasource = ds.getDatasource();
List<Result> results = datasource.getData().getResultset().getResults();

// we can not predict order
for (int i = 0; i < 10;) {
results.get(i).getFields().get(0).setValue("/element/" + String.valueOf(++i));
}
validate(datasource, new DateFieldDifferenceHandler());
return datasource;
}

@Test
Expand Down

0 comments on commit fa1bf07

Please sign in to comment.