Temporarily store data in ASP.NET MVC

Asked

Viewed 690 times

3

I need to store some strings temporarily in an ASP.NET MVC application, these strings need to be accessible by server-side application at any time and the application itself will be in charge of disposing of these stored strings.

What is the ideal way to accomplish this in ASP.NET MVC?

  • When you refer to the server would it be where the application is hosted? or another application that will access? Ta a little confusing that there.

  • Just a server? Is the volume large? Temporary how much? While the session lasts? Give more context.

  • 1

    @Marconciliosouza edited the question, server = server-side of the application, I wrote only to make clear that I want to have access to the data at any time, as if I were consulting a database.

  • @bigown why would it have more than one server? About the volume, as I said, it’s just a string, it’s basically an id. About the session time, as I said, the application will manage when the string will be deleted from that "Storage".

  • 1

    So this id can survive for several sessions? Just by having one ideach time on the server? It is a "static" data of the application and not of the session, it is not quite temporary, it is just unnecessary at all times?

  • Yes, it can survive for several sessions. But it won’t be stored forever in the application. In my case, this data has a lifespan of less than 3 hours.

Show 1 more comment

1 answer

3


Obviously it has several solutions and without knowing each detail I would not know to state which the best.

If you just need to be in the current application you can use the HttpContext.Application (See also the stately object). This is just a specific dictionary that can hold any data. Example of use. And examples applied.

Other more manual mechanisms can be used, some based on the cache system.

If you need something external to the application could even be a service that stores this in memory, but has simpler solution that should meet the requirements. Play in a file that can be read. I doubt you’ll find a simpler solution.

If you have competition problems from who will write this and do not want to deal on their own in the file play in a database, even if it is Sqlite. Many would already opt for this by default. If you already use it, it might even be better. If you use a database (probably), creating a table with a column and a row is so simple that I don’t see why not (there could be some reason, but nothing described indicates this).

It has more complex but unnecessary solutions.

Something that might help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.