@@ -0,0 +1,2981 @@
+/*%0A * Copyright 2017 Christian Aguirre %3CPvpaguirre@gmail.com%3E.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage uk.org.whoami.authme.datasource;%0A%0Aimport java.util.HashMap;%0A%0Aimport uk.org.whoami.authme.cache.auth.PlayerAuth;%0A%0Apublic class CacheDataSource implements DataSource %7B%0A%0A    private DataSource source;%0A    private final HashMap%3CString, PlayerAuth%3E cache = new HashMap%3CString, PlayerAuth%3E();%0A%0A    public CacheDataSource(DataSource source) %7B%0A        this.source = source;%0A    %7D%0A%0A    @Override%0A    public synchronized boolean isAuthAvailable(String user) %7B%0A        return cache.containsKey(user) ? true : source.isAuthAvailable(user);%0A    %7D%0A%0A    @Override%0A    public synchronized PlayerAuth getAuth(String user) %7B%0A        if(cache.containsKey(user)) %7B%0A            return cache.get(user);%0A        %7D else %7B%0A            PlayerAuth auth = source.getAuth(user);%0A            cache.put(user, auth);%0A            return auth;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public synchronized boolean saveAuth(PlayerAuth auth) %7B%0A        if (source.saveAuth(auth)) %7B%0A            cache.put(auth.getNickname(), auth);%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    @Override%0A    public synchronized boolean updatePassword(PlayerAuth auth) %7B%0A        if (source.updatePassword(auth)) %7B%0A            cache.get(auth.getNickname()).setHash(auth.getHash());%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    @Override%0A    public boolean updateSession(PlayerAuth auth) %7B%0A        if (source.updateSession(auth)) %7B%0A            cache.get(auth.getNickname()).setIp(auth.getIp());%0A            cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    @Override%0A    public int purgeDatabase(long until) %7B%0A        int cleared = source.purgeDatabase(until);%0A%0A        if (cleared %3E 0) %7B%0A            for (PlayerAuth auth : cache.values()) %7B%0A                if(auth.getLastLogin() %3C until) %7B%0A                    cache.remove(auth.getNickname());%0A                %7D%0A            %7D%0A        %7D%0A        return cleared;%0A    %7D%0A%0A    @Override%0A    public synchronized boolean removeAuth(String user) %7B%0A        if (source.removeAuth(user)) %7B%0A            cache.remove(user);%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    @Override%0A    public synchronized void close() %7B%0A        source.close();%0A    %7D%0A%0A    @Override%0A    public void reload() %7B%0A        cache.clear();%0A    %7D%0A%7D%0A

Create DataCacheSource.java