baked_file_system icon indicating copy to clipboard operation
baked_file_system copied to clipboard

remove file from memory after expire

Open kostya opened this issue 8 years ago • 4 comments

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)

kostya avatar Jul 05 '16 16:07 kostya

@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

schovi avatar Jul 05 '16 22:07 schovi

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

kostya avatar Jul 05 '16 22:07 kostya

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

kostya avatar Jul 05 '16 22:07 kostya

Inspiration https://github.com/sdogruyol/kemal-session/blob/master/src/kemal-session/base.cr

schovi avatar Nov 22 '16 20:11 schovi