looking for light-weight data persistence solution in perl

后端 未结 6 1464
离开以前
离开以前 2021-02-14 11:29

In my app I need to store some simple data both in memroy and in disk. A real database will be overkill in my case, so I need lighter one to handle the simple data persistence r

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-14 12:02

    You have several options:

    • Storable is a core module and is very efficient. It has some problems with portability, for example someone using an older version of Storable may not be able to read your data. Also, the endianness of the system creating and retrieving that data is important. The network order stoarge options help reduce the portability issues. You can store an arbitrary nested data structure to a file or string and restore it. Storable is supported only by Perl.

    • YAML is a text based format that works like storable--you can store and restore arbitrary structures to/from YAML files. YAML is nice because there are YAML libraries for several languages. It's not quite as speedy or space efficient as Storable.

    • JSON is a popular data exchange format with support in many languages. It is very much like YAML in both its strengths and weaknesses.

    • DBD::SQLite is a database driver for the DBI that allows you to keep a whole relational database in a single file. It is powerful and allows you work with many of the persistence tools that are aimed at other databases like MySQL and Postgres.

    • DBM::Deep is a convenient and powerful perl only module that allows efficient retrieval and modification of small parts of a large persistent data structures. Almost as easy to use as Storable, but far more efficient when dealing with only small portions of a large data structure.

    Update: I realized that I should mention that I have used all of these modules and depending on your particular needs, any of them could be "the right choice".

提交回复
热议问题