Add callback before prune to allow touching keepworthy guids
This commit is contained in:
parent
b08e75faa6
commit
145986d5ae
18
LibGUID.lua
18
LibGUID.lua
|
@ -1,10 +1,12 @@
|
|||
local lib = LibStub:NewLibrary("LibGUID", 1)
|
||||
if not lib then return end
|
||||
local guid_methods = guid_methods or {}
|
||||
local mixins = {'CreateGUIDObject'}
|
||||
local mixins = {'CreateGUIDObject', 'RegisterPrune', 'PruneGUIDCache'}
|
||||
lib.mixinTargets = lib.mixinTargets or {}
|
||||
lib.guidCache = lib.guidCache or {}
|
||||
lib.pruneInfo = lib.pruneInfo or {}
|
||||
local guidCache = lib.guidCache
|
||||
local pruneInfo = lib.pruneInfo
|
||||
local guidTypes = {
|
||||
["Player"] = true,
|
||||
["Creature"] = true,
|
||||
|
@ -28,7 +30,7 @@ end
|
|||
function guid_methods:Refresh()
|
||||
if(self['type'] == 'Player') then
|
||||
local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(self[1])
|
||||
if(name and name !== self['name']) then
|
||||
if(name and name ~= self['name']) then
|
||||
self['localizedClass'] = localizedClass
|
||||
self['englishClass'] = englishClass
|
||||
self['localizedRace'] = localizedRace
|
||||
|
@ -61,11 +63,17 @@ function lib:CreateGUIDObject(obj)
|
|||
end
|
||||
end
|
||||
end
|
||||
function lib:RegisterPrune(funcName)
|
||||
pruneInfo[self] = funcName
|
||||
end
|
||||
function lib:PruneGUIDCache(maxAge)
|
||||
local maxAge = maxAge or 3600
|
||||
local t = GetTime()
|
||||
for k, v in pairs(pruneInfo) do
|
||||
k[v]()
|
||||
end
|
||||
local maxAge = maxAge or 360
|
||||
local t = GetTime() - maxAge
|
||||
for guid, obj in pairs(guidCache) do
|
||||
if(obj['lastModified'] < t - maxAge) then
|
||||
if(obj['lastModified'] < t) then
|
||||
guidCache[guid] = nil
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue