Мы выполняем школьный проект, и у нас есть вопрос:
Если мы хотим создать нового пользователя, он не сможет сразу войти в систему.Поэтому мы решили изменить TTL на 5S, но это может быть неправильным решением.
На данный момент наш UserCache выглядит так, как TTL, сохраненный в нашем config.json для 5S.
Мы обеспокоены тем, что это не правильный вызов.Так что же делает TTL пропорционально UserCache?И какое может быть правильное решение?Мы только начали кодировать ..
С уважением, Каспер
// TODO: Постройте этот кеш и используйте его.(ИСПРАВЛЕНО) открытый класс UserCache {
// List of users
private ArrayList<User> users;
// Time cache should live. Definere en variabel vi kalder ttl.
private long ttl;
// Sets when the cache has been created
private long created;
// Vi har her lavet en konstruktør, hvor vi henter alle brugerne fra config klassen
public UserCache() {
this.ttl = Config.getUserTtl();
}
public ArrayList<User> getUsers(Boolean forceUpdate) {
// If we wish to clear cache, we can set force update.
// Otherwise we look at the age of the cache and figure out if we should update.
// If the list is empty we also check for new products
if (forceUpdate
|| ((this.created + this.ttl) <= (System.currentTimeMillis() / 1000L))
|| this.users.isEmpty()) {
// Get users from controller, since we wish to update.
ArrayList<User> users = UserController.getUsers();
// Set users for the instance and set created timestamp
this.users = users;
this.created = System.currentTimeMillis() / 1000L;
}
// Return the documents
return this.users;
}
}