Simple MySQL Cache

So i decided to make a simple mysql cache that will store tables in a table.
Find it at https://github.com/andreblue/mysql_cache_gmod
You simply register some details with lua and it will handle the rest. You can take a look at https://github.com/andreblue/mysql_cache_gmod/blob/master/lua/test_mysql_cache.lua to see how it works.

How would this work if you have a million rows in a table? This seems like a bad excuse to not use callback functions

Then better this: https://github.com/alexgrist/GLua-MySQL-Wrapper :zoid:

Thats a wraper which makes doing things easier with mysql. It does not cache the data unlike what this does. You could use both to do it.

I will add in some filtering later. That is the plan at least.

Why is your entire readme in bold.

Blame me sucking at markdown.

For what reason would you want to cache all records from database tables into an lua table?

I am not really understanding how this would be useful, to me this seems pointless.

Retrieving every record from tables and just storing in an lua table seems unnecessary, when on the other hand it would be much more effective to just run a query and get the necessary records.

Well, on one hand you’re storing a boatload of stuff in memory that you don’t need to.

On the other, now you have to worry about cache coherency.

It’s a win-win.

I feel like this is one of those situations where someone had a random idea in the shower, yet didn’t question why no one else had done this

It’s an answer to a question that never needs to be asked.

Why wait on mysql when you can just download moar ram!

Anything properly written will not have an issue with the response time of MySQL. If you are running into issues with it, you need to rethink how you’re doing it. If you come up with this method as a solution, you probably have a completely different problem than you came up with a solution for.

There is just honestly very little practical use for this.

Most gmod modules require that you wait for it to get back. I didnt like that as much.

You’ve completely defeated the purpose of retrieving data on-demand from an external database, good work!

Its kinda a yes and no on that. Some people dont want to have to wait on it.

Anyways, updated added to allow filtering.

If you don’t want to wait on it then you’re not using MySQL correctly. Literally the entire point is to retrieve data on-demand. If you don’t want that then use a text file and cache it when it loads. Or use SQLite.

Then don’t wait. Grab data you need when the server starts and cache it then, but that should be done on a situational basis. No use in caching everything and wasting memory.