Add-on:Common plugin cache: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>DonJBot
m (Wikipedia python library)
>TobiasTheCommie
No edit summary
Line 12: Line 12:


[[Category:Repo: Eden-pre]]
[[Category:Repo: Eden-pre]]
= Developers  =
== Setup ==
To use the cacheing service add the following to your py file.
  try:
    import StorageServer
  except:
    import storageserverdummy as StorageServer
  cache = StorageServer.StorageServer()
  cache.table_name = "PluginName" # Name of your plugni.
You can now access the caching service through the "cache" variable.
== cacheFunction(self, funct = False, *args) ==
Caching function results for one hour.
The function being cached must return a tupple ( function_return, status), a status of 200 means the result is ok and should be cached. Any other value and the function result will be returned, but not cached.
  def pi_count(self):
      def arccot(x, unity):
          sum = xpower = unity // x
          n = 3
          sign = -1
          while 1:
                xpower = xpower // (x*x)
                term = xpower // n
                if not term:
                        break
                sum += sign * term
                sign = -sign
                n += 2
          return sum
 
      digits = 40
      unity = 10**(digits + 10)
      pi = 4 * (4*arccot(5, unity) - arccot(239, unity))
      return (pi // 10**10, 200)
 
  result = cache.cacheFunction(pi_count) # This will call the pi_count function, save the result in the cache, and return the result.
  time.sleep(300)
  result = cache.cacheFunction(pi_count) # This will return the cached result
  time.sleep(3600)
  result = cache.cacheFunction(pi_count) # This will again call pi_count since the result is now considered stale.

Revision as of 21:31, 6 December 2011

Common plugin cache

See this add-on on the kodi.tv showcase

Author: TheCollective

Type: Services
Repo: Kodi.tv repo v21
Kodi.tv repo v20
Kodi.tv repo v19

Summary: Common caching api for xbmc plugins.
Home icon grey.png   ▶ Add-ons ▶ Common plugin cache

Installing

This add-on is installed from the Add-on browser located in Kodi as follows:

  1. Settings
  2. Add-ons
  3. Install from repository
  4. Services
  5. Common plugin cache
  6. Install


Developers

Setup

To use the cacheing service add the following to your py file.

 try:
   import StorageServer
 except:
   import storageserverdummy as StorageServer
 cache = StorageServer.StorageServer()
 cache.table_name = "PluginName" # Name of your plugni.

You can now access the caching service through the "cache" variable.

cacheFunction(self, funct = False, *args)

Caching function results for one hour.

The function being cached must return a tupple ( function_return, status), a status of 200 means the result is ok and should be cached. Any other value and the function result will be returned, but not cached.

 def pi_count(self):
     def arccot(x, unity):
         sum = xpower = unity // x
         n = 3
         sign = -1
         while 1:
               xpower = xpower // (x*x)
               term = xpower // n
               if not term:
                       break
               sum += sign * term
               sign = -sign
               n += 2
         return sum
  
     digits = 40
     unity = 10**(digits + 10)
     pi = 4 * (4*arccot(5, unity) - arccot(239, unity))
     return (pi // 10**10, 200)
 
 result = cache.cacheFunction(pi_count) # This will call the pi_count function, save the result in the cache, and return the result.
 time.sleep(300)
 result = cache.cacheFunction(pi_count) # This will return the cached result
 time.sleep(3600)
 result = cache.cacheFunction(pi_count) # This will again call pi_count since the result is now considered stale.