7 Months Ago
Fix cookie lib hash (#1779) test code: ```lua local key = "test" local function printState() PrintTable({ realval = sql.QueryValue( "SELECT value FROM cookies WHERE key = " .. SQLStr(key) ), cached = cookie.GetString(key), }) end cookie.Set(key, 1) -- set initial value printState() -- ok. cached but not commited so realval is nil for now timer.Simple(31, function() -- wait cache ttl (time to live) period -- Update cached value immediately but don't refresh cache's ttl so it's expires -- At this point, we also schedule a commit to the DB cookie.Set(key, 2) -- Because the caches ttl is expired, the cookie.GetString function should request a value from the DB -- But as we remember, in the previous step we just scheduled a value update -- It has not been commuted so the cache will be updated with the wrong value and contain the wrong value for the next 30 seconds printState() -- realval and cache values are both "1" -- Wait for scheduled commit timer.Simple(2, function() -- As stated before, cache now and for the next 30 seconds (28 seconds) will be wrong printState() -- We have "1" for cached value and "2" for real value in database end) end) ```