Kodi Community Forum

Full Version: [Release] Common plugin cache
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11
This is version 0.9.1 of a common plugin cache for XBMC.

This service will go to Final 1.0 with YouTube 3.0.

This service provides thread safe locking, data/settings storage, and an 1 day cache of function results.

The cache greatly cuts down on the time it take to reshow a listing after playback has finished, or just on directory change.

Implementation details can be found on the wiki.

http://wiki.xbmc.org/index.php?title=Add...ugin_cache

This is a dependency used by our other plugins, and we perform constant integration and unittesting during development

http://tc.tobiasussing.dk/jenkins/view/Cache%20Service/

Questions, requests, suggestions are welcome.

Note: Before the 1.0 final we do not promise the interface will stay locked.
After the 1.0 version there will be "DeprecatedFunction" warnings on changes for a limited time.

TheCollective
Hi, I'm trying to use cacheFunction to cash a json string. It seems to be saving but when I call cacheFunction again it doesn't seem to find the cache and runs the function again.

This is my code -
Code:
def get_json():
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        return(link, 200)

def Categories():
        result = cache.cacheFunction(get_json)
        data = json.loads(result[0])

Some debug output - http://pastebin.com/8kzQ2A7F

I'm sure it's something I'm not understanding :o Thanks for any help.
It should work as you have made it.

Could you try and remove the spaces from the tablename variable?
I had tried without the spaces but the '-' seems to of been the problem. I also tried using the addon id but I guess the '.' in the table name is a no go also. Using '_' doesn't seem to be a problem.

Thanks, good stuffSmile
those are some fucked up errors. That should not happen.

If anything the addon should handle malformed names by itself.

Thanks for reporting your problem.

ETA: Nice post number
Could anyone explain when/why to use lock() - unlock() ?
divingmule Wrote:Could anyone explain when/why to use lock() - unlock() ?

TL/DR: It is used to prevent race conditions. I don't expect many XBMC plugins to actually need this.

Detailed description:

If you have some code that can cause a race condition, you have to prevent it with lock/unlock.

One example would be the Simple Downloader.

When you queue an item it requests the current download queue from the common cache. Adds the new item. And saves the new updated queue to common cache.

Now if you were to queue two items very very quickly. you might end up with two threads trying to add a new item to the queue.

Thread 1) Load queue (Loads download 1, 2, 3, 4)
Thread 2) Load queue (Loads download 1, 2, 3, 4)
Thread 1) adds new download to queue ( queue is now 1, 2, 3, 4, 5)
Thread 2) adds new download to queue ( queue is now 1, 2, 3, 4, 6)
Thread 1) saves its updated queue to the common cache ( Saved queue is 1, 2, 3, 4, 5)
Thread 2) saves its updated queue to the common cache ( Saved queue is 1, 2, 3, 4, 6)

In this case the downloaded item called "5" will be "forgotten" because of the race condition between these two threads.

What lock/unlock gives you is.

Thread 1) Locks the queue
Thread 1) Load queue (Loads download 1, 2, 3, 4)
Thread 2) Tries to load queue. But queue is locked.
Thread 1) adds new download to queue ( queue is now 1, 2, 3, 4, 5)
Thread 1) saves its updated queue to the common cache ( Saved queue is 1, 2, 3, 4, 5)
Thread 1) Unlocks the queue

Or if you want to make it a little more advanced you can make it do.

Thread 1) Locks the queue
Thread 1) Load queue (Loads download 1, 2, 3, 4)
Thread 2) Tries to load queue. But queue is locked.
Thread 1) adds new download to queue ( queue is now 1, 2, 3, 4, 5)
Thread 1) saves its updated queue to the common cache ( Saved queue is 1, 2, 3, 4, 5)
Thread 1) Unlocks the queue
Thread 2) Locks the queue
Thread 2) Loads queue (Loads download 1, 2, 3, 4, 5)
Thread 2) adds new download to queue ( queue is now 1, 2, 3, 4, 5, 6)
Thread 2) saves its updated queue to the common cache ( Saved queue is 1, 2, 3, 4, 5, 6)
Thread 2) Unlocks the queue
Thanks for the detailed response.Smile
I am beta testing a new build for the Icefilms plugin that uses this common plugin cache. However, something is going wrong, and it's timing out. Here's the part of the log where it stops responding:
http://pastebin.com/MGAsyG50

Seems to only be happening to me, and the site is responding fine via a browser.
any ideas?
You are getting hit with a "Fallback error handling" function.

Could you enable debugging for the "Common plugin cache" and try again? (System -> Settings -> Addons -> Enabled -> Services -> Common plugin cache)

I am not sure why it is taking the server more than 10 seconds to reply(Thus hitting the fallback).
Sorry took so long. Im assuming the debug log just dumps into the same log: http://pastebin.com/Z8Ykdvd8
Entire log please Smile
Man, pastebin cut me off with this one, haha.

Here you go:
http://paste2.org/p/1864782

Thanks.
Hm, it is stalling because of a bug that has since been fixed.

But i believe the bug has been triggered by a faulty download in iceplugin originally(then replicated and made worse by the cache).

Clear your cache with:
rm ~/.xbmc/userdata/Database/commoncache.db

And try again.

If it still fails please send me a new log. Remember to clear the cache before every attempt.
TobiasTheCommie Wrote:Hm, it is stalling because of a bug that has since been fixed.

But i believe the bug has been triggered by a faulty download in iceplugin originally(then replicated and made worse by the cache).

Clear your cache with:
rm ~/.xbmc/userdata/Database/commoncache.db

And try again.

If it still fails please send me a new log. Remember to clear the cache before every attempt.

Worked! Thanks so much, I'm kind of an idiot. Good to know where the cache db is too, in case I run into it again. Wink
Pages: 1 2 3 4 5 6 7 8 9 10 11