plugin key-value store in split-state

Development-related discussion, including bundled plugins
Anchakor
Bear Rating Trainee
Bear Rating Trainee
Posts: 13
Joined: 23 Apr 2013, 02:44

plugin key-value store in split-state

Postby Anchakor » 28 Apr 2013, 16:43

Hi, I have a problem with the key-value store being in kind of split-state.
I use $this->host->get(...) and $this->host->set(...) both in hook_render_article_cdm and in different method which is called by ajax method. the problem is that if I update in that ajax-called-method the store by $this->host->set(...), $this->host->get(...) in the render hook still returns the old values, until I go to preferences and go back.
How can I fix this, or is there a better synchronization method between different http server requests?

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: plugin key-value store in split-state

Postby fox » 28 Apr 2013, 18:13

Yeah maybe session cache for this should be removed, it can cause problematic stuff like this.

https://github.com/gothfox/Tiny-Tiny-RS ... 3c15732924

Anchakor
Bear Rating Trainee
Bear Rating Trainee
Posts: 13
Joined: 23 Apr 2013, 02:44

Re: plugin key-value store in split-state

Postby Anchakor » 28 Apr 2013, 18:35

Well the cache is usually useful, so woudn't it be better to have it documented with a method of its invalidation, like $_SESSION["plugin_storage"] = false; no?

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: plugin key-value store in split-state

Postby fox » 28 Apr 2013, 18:47

I don't think the performance gained is worth the potential problems, let's run it like this for a bit and see if it's worth having it in the first place.

Anchakor
Bear Rating Trainee
Bear Rating Trainee
Posts: 13
Joined: 23 Apr 2013, 02:44

Re: plugin key-value store in split-state

Postby Anchakor » 28 Apr 2013, 23:07

Instead of using the key-value store (which I think is overkill and too resource intensive to read & write for every article rendering just to check a little thing, and also it seems to synchronize only on second request) I tried using the session variable, which I read is strongly concurrent, however it still doesn't work.
I have the ajax called method which writes into $_SESSION["mykey"][] = value; and then the article rendering hook which reads the $_SESSION["mykey"], prints debug info and clears it, however it is not synchronized. Any idea what is wrong? Maybe I need to session_start() manually in the ajax-called-method?

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: plugin key-value store in split-state

Postby fox » 28 Apr 2013, 23:25

Don't screw with session_start(), you will break things horribly. Also, yeah, in my personal experience you need to be wary while relying on sessions for concurrency, because of how they actually work, especially when there's ajax in the picture.

Best solution would be keeping whatever in a separate table which plugin may install or ask user to install if needed. It's more work, but it's how it should be done.

Simple key-value store is definitely not designed to be used like that, it is supposed to store simple plugin settings and whatnot where you don't really write often.

Anchakor
Bear Rating Trainee
Bear Rating Trainee
Posts: 13
Joined: 23 Apr 2013, 02:44

Re: plugin key-value store in split-state

Postby Anchakor » 29 Apr 2013, 00:40

Is there a some example how to introduce a new table with a plugin correctly?

I wish there was a simpler way to communicate a simple thing from a ajax-called-method to an article rendering hook...


Return to “Development”

Who is online

Users browsing this forum: No registered users and 4 guests