0

I want to be able to call on a list of files that are being processed by the server. The problem is, I want to call them on a web app (think React) whenever a user does something. i.e. a list of all possible choices and possible regex to narrow the list down.

How do you think I should store these names? I don't want to store it in the database for obvious reasons that database calls for something that won't change is pretty silly. It only needs to be read on startup of the application. So perhaps I can store it in memory on the server and just call through an api whenever I need.

Server is python and client is a mix of reactjs and other tech.

How should I store these files smartly?

  • What do you mean by "call"? – Winston Ewert Oct 2 '17 at 1:20
  • "call on"/ to retrieve. – insidesin Oct 2 '17 at 1:36
  • In Java, ".properties" files are used which are nothing else but a series of key=value lines. You could do something similar. Your key could be something like "files.<config>=<file1>,<file2>,..." where config would the name of the type of configuration based on the choices assuming the choices are reasonably limited. If not, you're kind of stuck with loading all files, then weeding out the ones you don't need and keeping it in memory. – Neil Oct 2 '17 at 10:36
  • Could you elaborate further? – Thomas Junk Oct 2 '17 at 12:23
1

I would hard code them in an array which you would setup in the root of your application.

If its a large list, or often changing then it might be worth writing some code to generate the code.

In my view the problem with dynamically generating a list like this is that you will inevitably have some special cases. '.gitignore' perhaps? You mention a regex to filter the list, but this will just add complexity.

A statically coded list with be visible in source control and you will be able to easily track changes to it.

  • The filter comes after recalling the list for use on the web/client. Do you see any pitfalls with storing it in memory for a server/client application? – insidesin Oct 2 '17 at 23:02
  • Hwever you store it, it eill be in memory when its read – Ewan Oct 3 '17 at 6:46
1

I would say that this sort of thing should probably be stored in a configuration file. If it doesn't need to change dynamically it doesn't need to be in the database, but you still want it accessible and changeable without delving into the code, and a configuration file is ideal for this. Even though you say it "won't change", in practice this is often a bad assumption so you want to allow the flexibility for it to change if necessary.

Your application can load from the file at start-up then keep the values static in memory after that, until it is restarted or reloads the configuration.

Since you don't specify what Python framework you're using I can't give any specifics on how to achieve this, but I imagine most have some way of specifying configuration files which are automatically loaded at startup. You can also check the configuration files into source control, similar to Ewan's approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.