What is GlobalState?

Hi, I am looking for a method to save variables as big as 1M. I found out GlobalState is pretty convinent. But I found no description about its performance. What is it? Is it capable of 1M data on server?

Any tip is welcome.

It’s the application wide persistent data.

It’s not volatile as caches, it’s persistent.

It’s not per user or per session, it’s application wide.

Usually it’s stored in an file named “state.bin” that is located under /protected/runtime.


If your data is per user, it should not be stored in globalState, however big it might be.

Thank you for your info. It is really helpful. But I am still wondering whether it is file cache?

If I am right, setGlobalState means serialize variables and save it to state.bin; getGlobalState means read the file and unseralize the data. Just like file-cache do. Am I right?

Um, well, setGlobalState and getGlobalState behave just as you stated. It’s a file, in short.

But it’s not a cache.

By definition, a cache is a copy of something that you can access by other means. We use it for performance reason. And we will not be surprised if a cache entry has disappeared, because we can still access the original data somehow.

What kind of data do you want to store?

If it is a result of a lengthy and heavy query, then you can consider using the query cache instead of global state. :)

Hi, I call it ‘cache’ because it is a big array from database :mellow: . I want to store all the users’ basic info into cache to reduce the query time. I already tried memory cache, but it doesn’t work well on Windows. I am trying query cache, maybe it work…

I see.

I would use query cache for it.

I found out Query Cache will vanish it the anything in the table changes… So it is not for a frequently updating table (I it should be so in most cases).

I am going back to the ‘file cache’ method…

?? Probably you have a misunderstanding about query cache.

Query cache and file cache are not in the same layer.

The former is for "what to cache" and the latter "where to cache".

Query cache caches the result of query to some media … that can be a file, db, or memory.

So we use query cache with some cache component that can be CFileCache, CMemCache, … etc.

When you don’t want to use query cache, then you have to take care of the validity of cache entries by yourself. I mean, you have to invalidate the cache entries and/or refresh them when the related tables are updated. It requires much more coding than simply using query cache. :)