use of no.stelar7.api.l4j8.basic.constants.api.URLEndpoint in project L4J8 by stelar7.
the class FileSystemCacheProvider method clearPath.
private void clearPath(Path p) throws IOException {
if (!Files.exists(p) || p.equals(home)) {
return;
}
LocalDateTime accessTime = ((FileTime) Files.readAttributes(p, "lastAccessTime").get("lastAccessTime")).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime nowTime = LocalDateTime.now();
long life = Duration.between(accessTime, nowTime).getSeconds() * 1000;
if (timeToLive != CacheProvider.TTL_USE_HINTS) {
if (timeToLive < life) {
// no point in deleting the folders..
if (Files.isDirectory(p)) {
return;
}
logger.debug("Data in cache is outdated, deleting...");
Files.deleteIfExists(p);
}
} else {
Path folder = p;
while (!folder.getParent().equals(home)) {
folder = folder.getParent();
}
URLEndpoint endpoint = URLEndpoint.valueOf(folder.getFileName().toString());
long expectedLife = hints.get(endpoint);
if (expectedLife < life) {
// no point in deleting the folders..
if (Files.isDirectory(p)) {
return;
}
logger.debug("Data in cache is outdated, deleting...");
Files.deleteIfExists(p);
}
}
}
use of no.stelar7.api.l4j8.basic.constants.api.URLEndpoint in project L4J8 by stelar7.
the class MySQLCacheProvider method clearOldCache.
@Override
public void clearOldCache() {
if (timeToLive == CacheProvider.TTL_INFINITY) {
return;
}
try (PreparedStatement stmt = sql.getConnection().prepareStatement("DELETE FROM ? WHERE ? < ?")) {
for (URLEndpoint endpoint : URLEndpoint.values()) {
stmt.setString(1, endpoint.name());
stmt.setString(2, COLUMN_INSERTED_AT);
stmt.setLong(3, System.currentTimeMillis() + getTimeToLive(endpoint));
stmt.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of no.stelar7.api.l4j8.basic.constants.api.URLEndpoint in project L4J8 by stelar7.
the class CacheDataKeys method createUpdateStatement.
public static String createUpdateStatement(URLEndpoint type, Object[] obj) {
Object[] filters = new Object[obj.length - 1];
System.arraycopy(obj, 1, filters, 0, obj.length - 1);
StringBuilder start = new StringBuilder("UPDATE ? SET ? = ?");
String[] keys = getKeysForType(type);
if (keys.length > 0) {
start.append(" WHERE ");
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
Object value = filters[i];
if ("1".equals(key)) {
continue;
}
start.append(key).append(" = ").append(value);
if (i < keys.length - 1) {
start.append(" AND ");
}
}
}
return start.toString();
}
use of no.stelar7.api.l4j8.basic.constants.api.URLEndpoint in project L4J8 by stelar7.
the class MySQLCacheProvider method clearOldCache.
@Override
public void clearOldCache() {
if (timeToLive == CacheProvider.TTL_INFINITY) {
return;
}
try (PreparedStatement stmt = sql.getConnection().prepareStatement("DELETE FROM ? WHERE ? < ?")) {
for (URLEndpoint endpoint : URLEndpoint.values()) {
stmt.setString(1, endpoint.toString());
stmt.setString(2, COLUMN_EXPIRES_AT);
stmt.setLong(3, System.currentTimeMillis() + getTimeToLive(endpoint));
stmt.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of no.stelar7.api.l4j8.basic.constants.api.URLEndpoint in project L4J8 by stelar7.
the class SummonerBuilder method get.
/**
* gets a summoner based on the parameters passed to the builder
*
* @return Summoner
*/
public Summoner get() {
DataCallBuilder builder = new DataCallBuilder().withPlatform(this.platform);
URLEndpoint endpoint = null;
if (accId > 0) {
builder.withURLParameter(Constants.ACCOUNT_ID_PLACEHOLDER, String.valueOf(this.accId));
endpoint = URLEndpoint.V3_SUMMONER_BY_ACCOUNT;
}
if (sumId > 0) {
builder.withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, String.valueOf(this.sumId));
endpoint = URLEndpoint.V3_SUMMONER_BY_ID;
}
if (name.length() > 0) {
builder.withURLParameter(Constants.SUMMONER_NAME_PLACEHOLDER, Utils.normalizeSummonerName(this.name));
endpoint = URLEndpoint.V3_SUMMONER_BY_NAME;
}
builder.withEndpoint(endpoint);
Optional chl = DataCall.getCacheProvider().get(endpoint, this.platform, this.accId, this.sumId, this.name);
if (chl.isPresent()) {
return (Summoner) chl.get();
}
Object sob = builder.build();
if (sob instanceof Pair) {
return null;
}
DataCall.getCacheProvider().store(endpoint, sob, this.platform, this.accId, this.sumId, this.name);
return (Summoner) sob;
}
Aggregations