schovi / baked_file_system

Virtual File System for Crystal language. Embedding your assets into final binary.
MIT License
177 stars 18 forks source link

remove file from memory after expire #1

Open kostya opened 8 years ago

kostya commented 8 years ago

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)

schovi commented 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
kostya commented 8 years ago

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 commented 8 years ago

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

schovi commented 7 years ago

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