Open kostya opened 8 years ago
@kostya Is there any native tool for that?
My naive idea is to do it manually like:
def read
return @string if @string
@string = ....
if @expire_in
spawn do
sleep @expire_id
@string = nil
end
end
@string
end
i am using every
pattern, https://gist.github.com/kostya/7388768b1363e95852c5367a16b5900f#file-xx-cr-L19
i think you should create one loop for class, like this:
every(10.seconds) do
@files.each do |file|
file.expire! if file.expired?
end
end
hm, btw you can you also https://github.com/kostya/memory_cache, this is actually memory cache with expires, but this is not supported access time right now
for each file add access time, and allow to expire rare-access keys. this is should save process memory.
like this:
BakedFileSystem.load("dir", expire_in: 1.hour)