Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Global/persistant storage for server apps?
Fri, Aug 26 2022 6:05 PMPermanent Link

Ralf Mimoun

Next topic Smile

I need to store an integer in my server app. Not in a database, not in a cookie, just in the server app. Background: I need to delete expired tokens from a table, but I don't want to do this on every single request.

What I need is a way to store an integer from some code in MainReqHandler, so that I can get that value back next time when a request is received.

Things that don't work (at least for me):

- variable in MainRegHandler
- property in MainRegHandler
- class variable
- class property
- global variable in the same unit
- global variable in another unit

You can assing a value to all of these things, but next time (eg. reloading the page via browser), they are 0 again.

The server creates a new application environment plus request handler(s) for each request, so everything is nicely capsuled. Too nicely for my case SmileAnd yes, I know that accessing something from multiple threads is not that simple. Once I coded for a Thinking Machine CM5 with 512 nodes, been there, done that Smile
Fri, Aug 26 2022 6:10 PMPermanent Link

Ralf Mimoun

Btw, you can create multiple request handler in one server app. But: Why? It would be great if each request handler could predent a different part of the URL path, or if OnHandleRequest would have a Handled parameter (yes, not possible, no VAR parameters) so you could chain the request handlers. But I have found no hint in the documentation.
Fri, Aug 26 2022 8:04 PMPermanent Link

erickengelke

Ralf Mimoun wrote:

> Next topic Smile

> I need to store an integer in my server app. Not in a database, not in a cookie, just in the server app.
> Background: I need to delete expired tokens from a table, but I don't want to do this on every single request.

I'm not an expert in Elevate's server because I've never used it for a production system.

I'm a little confused, because you want it to be REST, which is stateless, but it sounds like you want to maintain state.

There are a couple of ways I can see doing this in any environment, so it would be equally applicable to EWB as any other.

- Database, by userid
- file on server (as Apache does) matched with cookie on client
- cookie on client
- JSON Web Token (see jwt.io for details) entirely stored on client, but verified by server, is stateless but has timeout, authentication, etc,  What  OpenID connect uses behind the scenes

I use JWTs a lot and recommend them as they are fast and secure, and don't require a DB or file lookup, and are great for clusters or other systems with multiple servers without shared memory.    I don't have handy EWB Server code for generating or testing them, but jwt.io includes link to Pascal code for genating/testing them.

Erick
EWB Programming Books and Component Library
http://www.erickengelke.com
Sat, Aug 27 2022 6:37 AMPermanent Link

Ralf Mimoun

Erick,

no, my REST stuff will be totally stateless. I have to trigger a cleanup job, like

DELETE FROM Token WHERE CreatedAt < CURRENT_TIMESTAMP - 60000;

Maintenance, not related to the client request. Except that I want to use the client request as a trigger.


erickengelke wrote:

Ralf Mimoun wrote:

> Next topic Smile

> I need to store an integer in my server app. Not in a database, not in a cookie, just in the server app.
> Background: I need to delete expired tokens from a table, but I don't want to do this on every single request.

I'm not an expert in Elevate's server because I've never used it for a production system.

I'm a little confused, because you want it to be REST, which is stateless, but it sounds like you want to maintain state.

There are a couple of ways I can see doing this in any environment, so it would be equally applicable to EWB as any other.

- Database, by userid
- file on server (as Apache does) matched with cookie on client
- cookie on client
- JSON Web Token (see jwt.io for details) entirely stored on client, but verified by server, is stateless but has timeout, authentication, etc,  What  OpenID connect uses behind the scenes

I use JWTs a lot and recommend them as they are fast and secure, and don't require a DB or file lookup, and are great for clusters or other systems with multiple servers without shared memory.    I don't have handy EWB Server code for generating or testing them, but jwt.io includes link to Pascal code for genating/testing them.

Erick
EWB Programming Books and Component Library
http://www.erickengelke.com
Sat, Aug 27 2022 7:09 AMPermanent Link

Ralf Mimoun

Problem solved. I use the storage that I have on the server: the hard drive SmileA simple file in the temp directory, works great.
Image