4 // CICache for quickly reading data that is hard to decompress yet used
7 // Actual caching is done in the File object
8 // the CICache keeps files open while rendering.
10 // Since the CICache outlives EDLs it must copy every parameter given to it.
12 // Files given as arguments must outlive the cache.
14 #include "arraylist.h"
21 #include "pluginserver.inc"
22 #include "preferences.inc"
26 class CICacheItem
: public ListItem
<CICacheItem
>
29 CICacheItem(CICache
*cache
, File
*file
);
30 CICacheItem(CICache
*cache
, Asset
*asset
);
35 int64_t counter
; // number of age calls ago this asset was last needed
36 // assets used in the last render have counter == 1
37 Asset
*asset
; // Copy of asset. CICache should outlive EDLs.
44 class CICache
: public List
<CICacheItem
>
48 Preferences
*preferences
,
49 ArrayList
<PluginServer
*> *plugindb
);
52 friend class CICacheItem
;
54 // Enter a new file into the cache which is already open.
55 // If the file doesn't exist return the arguments.
56 // If the file exists delete the arguments and return the file which exists.
57 void update(File
* &file
);
58 void set_edl(EDL
*edl
);
60 // open it, lock it and add it to the cache if it isn't here already
61 File
* check_out(Asset
*asset
);
63 // unlock a file from the cache
64 int check_in(Asset
*asset
);
66 // delete an entry from the cache
67 // before deleting an asset, starting a new project or something
68 int delete_entry(Asset
*asset
);
69 int delete_entry(char *path
);
71 // increment counters after rendering a buffer length
72 // since you can't know how big the cache is until after rendering the buffer
73 // deletes oldest assets until under the memory limit
78 ArrayList
<PluginServer
*> *plugindb
;
81 int delete_oldest(); // returns 0 if successful
82 // 1 if nothing was old
83 int64_t get_memory_usage();
89 // to prevent one from checking the same asset out before it's checked in
90 // yet without blocking the asset trying to get checked in
91 // use a seperate mutex for checkouts and checkins
92 Mutex check_in_lock
, check_out_lock
, total_lock
;
95 Preferences
*preferences
;