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 // the cache is implemented with a lookup map which acts as storage backend
16 // the checked_out list keeps all checked out items
17 // when items are checked back in, they are moved to the head of the checked_in list
18 // age expiry is done by removing elements from the tail of the checked_in list
20 #include "arraylist.h"
23 #include "condition.inc"
27 #include "pluginserver.inc"
28 #include "preferences.inc"
35 CICacheItem(CICache
*cache
, EDL
*edl
, Asset_GC asset
);
40 // Number of last get or put operation involving this object.
41 Asset_GC asset
; // Copy of asset. CICache should outlive EDLs.
47 CICacheItem_plist::iterator list
;
54 CICacheItem_map items
;
55 CICacheItem_plist checked_in
;
56 CICacheItem_plist checked_out
;
60 CICache(Preferences
*preferences
,
61 ArrayList
<PluginServer
*> *plugindb
);
64 friend class CICacheItem
;
66 // Enter a new file into the cache which is already open.
67 // If the file doesn't exist return the arguments.
68 // If the file exists delete the arguments and return the file which exists.
69 // void update(File* &file);
70 // void set_edl(EDL *edl);
72 // open it, lock it and add it to the cache if it isn't here already
73 // If it's already checked out, the value of block causes it to wait
74 // until it's checked in.
75 File
* check_out(Asset_GC asset
, EDL
*edl
, int block
= 1);
77 // unlock a file from the cache
78 int check_in(Asset_GC asset
);
80 // delete an entry from the cache
81 // before deleting an asset, starting a new project or something
82 int delete_entry(Asset_GC asset
);
83 int delete_entry(char *path
);
84 // Remove all entries from the cache.
87 // Get ID of oldest member.
88 // Called by MWindow::age_caches.
89 int64_t get_memory_usage();
91 // Called by age() and MWindow::age_caches
92 // returns 1 if nothing was available to delete
96 // Called by check_in() and modules.
97 // deletes oldest assets until under the memory limit
98 // iterations is the upper limit how much much items will be removed from the cache,
99 // use -1 for a full aging cycle (remove items until preferences.cache_size is reached)
100 void age(int iterations
);
105 ArrayList
<PluginServer
*>* plugindb
;
107 const Preferences
& preferences
;
110 int64_t get_memory_usage_unlocked();
112 // for deleting items
116 // to prevent one from checking the same asset out before it's checked in
117 // yet without blocking the asset trying to get checked in
118 // use a seperate mutex for checkouts and checkins
120 Condition
* check_out_lock
;
129 // c-file-style: "linux"