Sinatra with a persistent variable

后端 未结 3 1342
甜味超标
甜味超标 2020-12-31 07:28

My sinatra app has to parse a ~60MB XML-file. This file hardly ever changes: on a nightly cron job, It is overwritten with another one.

Are there tricks or ways to

3条回答
  •  感动是毒
    2020-12-31 08:10

    Two options:

    • Save the parsed file to a new file and always read that one.

    You can save in a file – serialize - a hash with two keys: 'last-modified' and 'data'.

    The 'last-modified' value is a date and you check in every request if that day is today. If it is not today then a new file is downloaded, parsed and stored with today's date.

    The 'data' value is the parsed file.

    That way you parse just once time, sort of a cache.

    • Save the parsed file to a NoSQL database, for example redis.

提交回复
热议问题