B4J Question [Server] Handling Cache

aeric

Expert
Licensed User
Longtime User
8. Enable or disable Caching

I guess you can use server.CreateThreadSafeMap
but it may be better to wrap a library like:

This is something beyond my knowledge and always a nightmare of mine when developing web applications.

If I want to build a web framework/application, I need to consider/overcome this problem. Caching can be a culprit to the issue of the static content not refresh. This usually happen if I overwrite the CSS or replace a new image with the same file name. The workaround is to append a new value to the GET request in the calling URL to force the server thinks that this resource should not already existed.

My question is, if I generate dynamic content from the database query or programming function to generate some kind of data model to pass to a template engine like FreeMarker, would I getting any issue? I am referring to jServer (jetty) application.
freemarker
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
The nature of HTML solution is that you send information to the user (that's under your control) and the user can provide information (which is not under your full control). Annyway, the result is in the DOM.
The underlying challenge is of course what is the displayed information worth? You can choose to read out the information displayed by the DOM so that the stored information is equal to what the user sees when (s)he give a update command therby ignoring the previously displayed value in an older situation.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
In the context of servers static has a different meaning.
Usually it means that it is the same now a minute ago and a minute from now.

But on servers it means that you will send html that doesn't need to change in order to be seen.

Think of Vue, Vue is dynamic because you have to send the JavaScript to the browser and then the page is made on the browser.

This html doesn't have to come from a file, usually it will not, it can be a string created from a stringbuilder in B4j.


I generate dynamic
To have the concept clear, you will create static content from dynamic sources.


would I getting any issue?
None. In the past frameworks like ASP handled this so wrong that broke our minds forever, you can pass anything you want and the browser will render it just fine.


FreeMarker
Free marker allows you to mix a template with a dynamic content and convert that into a string that will be sent thru the resp class to the browser.

You don't call the template directly nor create an html file from the result.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
When I meant by cache (like maps and lettuce) is that at some point the database may reach a limit of connections or processing,

So instead of calling the db form something continuous like session handling, its better to use a cache system

Btw, jetty already uses a cache system called sessions in the request class.

I don't want to worry about it
By all means, don't. I use my framewrok with 100 hundred customers concurrently and I haven't hit a single issue on performance.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
What was wrong?
what is wrong. i made an app with ASP a short time ago with what was the latest version (5.x) and i had to press F5 everytime to recache everything on the server. This is a mecanism they use so they spare some IO, it may be helpful in the past when we used HDD but on current NVME era, it is nonsense.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
what is wrong. i made an app with ASP a short time ago with what was the latest version (5.x) and i had to press F5 everytime to recache everything on the server. This is a mecanism they use so they spare some IO, it may be helpful in the past when we used HDD but on current NVME era, it is nonsense.
You worked on ASP .NET Core?
I never work on something beyond .NET 4.5
I am not sure how terrible it is.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
When I meant by cache (like maps and lettuce) is that at some point the database may reach a limit of connections or processing,

So instead of calling the db form something continuous like session handling, its better to use a cache system

Btw, jetty already uses a cache system called sessions in the request class.


By all means, don't. I use my framewrok with 100 hundred customers concurrently and I haven't hit a single issue on performance.
Do you have example how I can I mplement lettuce in jServer? I need to create a Redis client?
What is jetty build-in cache system? How is it different? Any example?
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
You worked on ASP .NET Core?
Yes i did

I never work on something beyond .NET 4.5
It gets better and better, yet i prefer Jserver a 100 times

I am not sure how terrible it is.
It is not, there are better things

Do you have example how I can I mplement lettuce in jServer?
i do not sorry, i played with it directly on java.

need to create a Redis client?
Start installing Redis SERVER on your PC, i think you cant install it on windows, if that is so you may want to use one form the Cloud
you dont need a redis client, Lettuce and therefore your app will be the redis client!

What is jetty build-in cache system
in your handlers you have a req object (servletrequest)
the cache is in:
req.GetSession
and the methods
GetAttribute
SetAttribute

these 2 work like if you were connecting to redis, the difference is that if you kill the server the cache is cleaned (thats actually what a cache is, ephimeral)
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
etty build-in cache system
by the way, one of the features of the jetty cache is that you can save Objects like classes and maps and not only scalar values (like strings) therefore you may find it more useful at the start of your project than redis
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Laragon server
i am not familiar with laragon but Redis uses a TCP connection with a port. if you have the IP and the port that redis is using you can actually issue some commands to it.

if you want to begin playing with redis then install the redis-cli
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
i am not familiar with laragon but Redis uses a TCP connection with a port. if you have the IP and the port that redis is using you can actually issue some commands to it.

if you want to begin playing with redis then install the redis-cli
I have checked on the UI for Redis from Laragon days ago. It just look like a MySQL db for me.

1656604950101.png
1656604998795.png
 
Last edited:
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
It just look like a MySQL db for me.
It is kinda similar, you could say that redis is a NOSQL database like mongo,

The extra that redis gives you is in memory data handling and a pub sub system. The later is just for advanced stuff
 
Upvote 0
Top