Store static data in an array or in a database?

We always have static data that can be saved in a file as an array or saved in a database table in our web project. So which one is preferable?

In my opinion, arrays have some advantages:

  • More flexible (this can be any structure that defines a truly complex relationship)
  • Better performance (it will be loaded into memory, which will have better read / write performance compared to database I / O).

But my colleague claimed that he prefers the DB approach, since it can support a single data storage interface and be more flexible.

So what should be preferred? Or how can we choose? Or should we prefer one in some scenario and another in other scenarios? what are the scenarios?

EDIT:

Let me clarify something. Indeed, just like Benjamin made changes to the header, the data that we want to save in the array (file) will not change so often, which means that the code will not change the value of the array at runtime. If the data changes very often, I will use DB without a doubt. That's why I made such a record.

And sometimes it’s hard to keep some very complex relationships, for example:

Task = {
  "1" : {
    "name" : "xx",
    "requirement" : {
          "level" : 5,
          "money" : 100,
     }
   ...
 }

(python dict ), ( , , , ). .

, ? DB, ?

.

+5
6

"" , DB. , , , . -.

Edit

OP , , (, ).

  • Concurrency: , . , .
  • . , , , . , . , , .
  • : . , , . IWO, , . , - , ()? - (, ).
  • . , .., . , "", ? .
  • . . / , , .
+3

/:

  • ? : Db, :
  • ? : Db, :
  • ? : Db, No: File,
  • ? : /, : Db
  • ? : db, :

, , , .

+3

, , comp sci . ? , . db, . - memcache jtreecache.

+2

, , .

( ) , (, thosands ). , , , .

0

, Java, Spring ?

bean .

Java.

0

Yes, I agree with your implied assessment that databases are overused and basic flat files can work in a variety of scenarios. If your application is read-only (and records are made by the administrator when the application is reloaded), I would definitely go with the file. Even if the application writes to the file, but only in add mode (vs random inserts / updates) in one stream, I would also use the file. Everything else - you need a real database with random updates, queries, concurrency, etc.

0
source

All Articles