Add an option to disable all caching (useful if you use website

registration system)
This commit is contained in:
vanhec_a 2015-10-12 15:49:19 +02:00
parent 5e991f7f42
commit 39ab41f542
3 changed files with 33 additions and 18 deletions

View File

@ -102,9 +102,15 @@ public class MySQL implements DataSource {
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
config.setUsername(this.username);
config.setPassword(this.password);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
if (Settings.isMySQLWebsite)
{
config.addDataSourceProperty("cachePrepStmts", "false");
}
else {
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
}
config.addDataSourceProperty("autoReconnect", false);
config.setInitializationFailFast(true); // Don't start the plugin if the database is unavariable
config.setMaxLifetime(180000); // 3 Min
@ -197,6 +203,8 @@ public class MySQL implements DataSource {
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player' AFTER " + columnLogged + ";");
}
if (Settings.isMySQLWebsite)
st.execute("SET GLOBAL query_cache_size = 0; SET GLOBAL query_cache_type = 0;");
} finally {
close(rs);
close(st);

View File

@ -68,7 +68,7 @@ public final class Settings extends YamlConfiguration {
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect,
customAttributes, generateImage, isRemoveSpeedEnabled;
customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite;
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
@ -275,6 +275,7 @@ public final class Settings extends YamlConfiguration {
forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole");
customAttributes = configFile.getBoolean("Hooks.customAttributes");
generateImage = configFile.getBoolean("Email.generateImage", true);
isMySQLWebsite = configFile.getBoolean("DataSource.mySQLWebsite", false);
// Load the welcome message
getWelcomeMessage();
@ -476,6 +477,10 @@ public final class Settings extends YamlConfiguration {
set("DataSource.mySQLRealName", "realname");
changes = true;
}
if (!contains("DataSource.mySQLQueryCache")) {
set("DataSource.mySQLWebsite", false);
changes = true;
}
if (changes) {
plugin.getLogger().warning("Merged new Config Options - I'm not an error, please don't report me");

View File

@ -43,6 +43,8 @@ DataSource:
mySQLlastlocWorld: world
# Column for RealName
mySQLRealName: realname
# Enable this when you allow registration through a website
mySQLWebsite: false
settings:
sessions:
# Do you want to enable the session feature?