Hello, I recently updated my script to load it's config from a webpage so I don't have to update it on all my different servers when I make changes. It seems to work fine except for when I refresh it. When I refresh it doesn't get the latest result. It will say that it has worked even if I delete the config file from the webserver. It's almost as if http.Fetch has a cache of some sort.
plt_config.lua (in autorun)
[CODE]
plt_conf_file = "http://porchlight.rpk.bz/config.lua"
function plt_conf_overrides()
plt_cooldowntime = 20
print("[Porchlight] Loaded override config successfully.")
end
[/CODE]
plt_main.lua (in autorun)
[CODE]
function plt_conf_initf(reloaded)
print("[Porchlight] Starting loading config file \"" .. plt_conf_file .. "\".")
http.Fetch( plt_conf_file,
function( body, len, headers, code )
print("[Porchlight] HTTP CODE : " .. code)
if code == 200 then
RunString( body, "plt_conf_loader", true )
plt_conf_overrides()
if reloaded then
print("[Porchlight] Config file reloaded successfully.")
end
else
print("[Porchlight] ERROR : Config loaded unsuccessfully.")
end
end,
function( error )
print("[Porchlight] ERROR : Config loaded unsuccessfully.")
end
)
end
hook.Add( "Initialize", "plt_conf_inith", plt_conf_initf(false) )
[/CODE]
Running plt_conf_initf() again will return
[CODE]
[Porchlight] Starting loading config file "http://porchlight.rpk.bz/config.lua".
[Porchlight] HTTP CODE : 200
[Porchlight] Loaded base config successfully.
[Porchlight] Loaded override config successfully.
[/CODE]
even if config.lua doesn't exist on the webserver. Is it possible that it does this because the config file is so large? Is there a better way I should be doing this? Or if there is a cache, how can I clear it every time the function runs?
Okay, so I've made myself a workaround.
[CODE]plt_conf_file_mod = plt_conf_file .. "?" .. tostring(math.random( 1, 99999 )) .. "=" .. tostring(math.random( 1, 99999 ))[/CODE]
I redefine the url so it creates random meaningless php vars like config.lua?91571=21238, and it works. However, this solution feels messy and imperfect.
This makes me more confident in my cache theory. There has to be a way just to clear the stored page, right?
Ya sure there isn't a CDN like cloudflare doing all the caching? A completely lazy way to guarantee no caching do it is to use POST instead of GET.
[QUOTE=Rone_;51368578]Okay, so I've made myself a workaround.
[CODE]plt_conf_file_mod = plt_conf_file .. "?" .. tostring(math.random( 1, 99999 )) .. "=" .. tostring(math.random( 1, 99999 ))[/CODE]
I redefine the url so it creates random meaningless php vars like config.lua?91571=21238, and it works. However, this solution feels messy and imperfect.
This makes me more confident in my cache theory. There has to be a way just to clear the stored page, right?[/QUOTE]
just use os.time() bro
Edit your .htaccess to prevent .lua caching
[code]
<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
[/code]
[QUOTE=Potatofactory;51369322]Edit your .htaccess to prevent .lua caching[/QUOTE]
Thank you. That fixed it. Needed to enable mod_headers however.
[QUOTE=pierre0158;51368743]just use os.time() bro[/QUOTE]
:mindblown:
Sorry, you need to Log In to post a reply to this thread.