+/** Release a service's cache items.
+ *
+ * \private \memberof mlt_service_s
+ * \param self a service
+ */
+
+void mlt_service_cache_purge( mlt_service self )
+{
+ mlt_properties caches = mlt_properties_get_data( mlt_global_properties(), "caches", NULL );
+
+ if ( caches )
+ {
+ int i = mlt_properties_count( caches );
+ while ( i-- )
+ {
+ mlt_cache_purge( mlt_properties_get_data_at( caches, i, NULL ), self );
+ mlt_properties_set_data( mlt_global_properties(), mlt_properties_get_name( caches, i ), NULL, 0, NULL, NULL );
+ }
+ }
+}
+
+/** Lookup the cache object for a service.
+ *
+ * \private \memberof mlt_service_s
+ * \param self a service
+ * \param name a name for the object
+ * \return a cache
+ */
+
+static mlt_cache get_cache( mlt_service self, const char *name )
+{
+ mlt_cache result = NULL;
+ mlt_properties caches = mlt_properties_get_data( mlt_global_properties(), "caches", NULL );
+
+ if ( !caches )
+ {
+ caches = mlt_properties_new();
+ mlt_properties_set_data( mlt_global_properties(), "caches", caches, 0, ( mlt_destructor )mlt_properties_close, NULL );
+ }
+ if ( caches )
+ {
+ result = mlt_properties_get_data( caches, name, NULL );
+ if ( !result )
+ {
+ result = mlt_cache_init();
+ mlt_properties_set_data( caches, name, result, 0, ( mlt_destructor )mlt_cache_close, NULL );
+ }
+ }
+
+ return result;
+}
+
+/** Put an object into a service's cache.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \param name a name for the object that is unique to the service class, but not to the instance
+ * \param data an opaque pointer to the object to put into the cache
+ * \param size the number of bytes pointed to by data
+ * \param destructor a function that releases the data
+ */
+
+void mlt_service_cache_put( mlt_service self, const char *name, void* data, int size, mlt_destructor destructor )
+{
+ mlt_log( self, MLT_LOG_DEBUG, "%s: name %s object %p data %p\n", __FUNCTION__, name, self, data );
+ mlt_cache cache = get_cache( self, name );
+
+ if ( cache )
+ mlt_cache_put( cache, self, data, size, destructor );
+}
+
+/** Get an object from a service's cache.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \param name a name for the object that is unique to the service class, but not to the instance
+ * \return a cache item or NULL if an object is not found
+ * \see mlt_cache_item_data
+ */
+
+mlt_cache_item mlt_service_cache_get( mlt_service self, const char *name )
+{
+ mlt_log( self, MLT_LOG_DEBUG, "%s: name %s object %p\n", __FUNCTION__, name, self );
+ mlt_cache_item result = NULL;
+ mlt_cache cache = get_cache( self, name );
+
+ if ( cache )
+ result = mlt_cache_get( cache, self );
+
+ return result;
+}
+
+/** Set the number of items to cache for the named cache.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \param name a name for the object that is unique to the service class, but not to the instance
+ * \param size the number of items to cache
+ */
+
+void mlt_service_cache_set_size( mlt_service self, const char *name, int size )
+{
+ mlt_cache cache = get_cache( self, name );
+ if ( cache )
+ mlt_cache_set_size( cache, size );
+}
+
+/** Get the current maximum size of the named cache.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \param name a name for the object that is unique to the service class, but not to the instance
+ * \return the current maximum number of items to cache or zero if there is an error
+ */
+
+int mlt_service_cache_get_size( mlt_service self, const char *name )
+{
+ mlt_cache cache = get_cache( self, name );
+ if ( cache )
+ return mlt_cache_get_size( cache );
+ else
+ return 0;
+}