Press on the image to return to the main documentation page.
Cache
Written by Fr\u00e9d\u00e9ric Leneuf-Magaud
List of types:
Cache
Cache
Events:
CopyDone(Key As String, Error As Boolean)
PutDone(Key As String, Error As Boolean)
GetDone(Key As String, Obj As Object)
Members:
BitmapSize
(
bitmap
As
BitmapWrapper
)
As
Long
BufferSize
As
Int
ClearDiskCache
ClearMemoryCache
CloseAndClearDiskCache
CloseDiskCache
CopyFileToDisk
(
key
As
String
,
dir
As
String
,
filename
As
String
)
CopyFileToDisk_Async
(
key
As
String
,
dir
As
String
,
filename
As
String
,
eventPrefix
As
String
)
DiskFree
As
Long
DiskJournal
As
List
DiskList
As
Map
DiskUsed
As
Long
FreeMemory
As
Long
[read
only]
GetBitmap
(
key
As
String
,
updateMemory
As
Boolean
)
As
android
.
graphics
.
Bitmap
GetBitmap_Async
(
key
As
String
,
updateMemory
As
Boolean
,
eventPrefix
As
String
)
GetBitmapFromDisk
(
key
As
String
,
colorReduction
As
Boolean
)
As
android
.
graphics
.
Bitmap
GetBitmapFromDisk_Async
(
key
As
String
,
colorReduction
As
Boolean
,
eventPrefix
As
String
)
GetBitmapFromMemory
(
key
As
String
)
As
android
.
graphics
.
Bitmap
GetDirectory
As
String
GetObjectFromDisk
(
key
As
String
)
As
Object
GetObjectFromDisk_Async
(
key
As
String
,
eventPrefix
As
String
)
GetStringFromDisk
(
key
As
String
)
As
String
Initialize
(
memoryCachePct
As
Byte
,
diskCacheSize
As
Long
,
diskCacheDir
As
String
)
IsClosed
As
Boolean
IsInMemory
(
key
As
String
)
As
Boolean
IsOnDisk
(
key
As
String
)
As
Boolean
MaxMemory
As
Long
[read
only]
MemoryEvictionCount
As
Int
MemoryFree
As
Int
MemoryHitCount
As
Int
MemoryList
As
Map
MemoryMissCount
As
Int
MemoryPutCount
As
Int
MemoryUsed
As
Int
PutBitmapInMemory
(
key
As
String
,
bitmap
As
BitmapWrapper
)
As
Boolean
PutBitmapOnDisk
(
key
As
String
,
bitmap
As
BitmapWrapper
,
format
As
String
,
quality
As
Int
)
PutBitmapOnDisk_Async
(
key
As
String
,
bitmap
As
BitmapWrapper
,
format
As
String
,
quality
As
Int
,
eventPrefix
As
String
)
PutObjectOnDisk
(
key
As
String
,
obj
As
Object
)
PutObjectOnDisk_Async
(
key
As
String
,
obj
As
Object
,
eventPrefix
As
String
)
PutStringOnDisk
(
key
As
String
,
value
As
String
)
RemoveBitmapFromMemory
(
key
As
String
)
RemoveFromDisk
(
key
As
String
)
As
Boolean
Members description:
BitmapSize
(
bitmap
As
BitmapWrapper
)
As
Long
Returns the size in bytes of the given bitmap.
BufferSize
As
Int
Gets/sets the buffer size of the disk cache. By default, it is set to the block size of the filesystem.
ClearDiskCache
Deletes all files in the cache directory including files that weren't created by the cache.
ClearMemoryCache
Clears the memory cache holding bitmaps.
CloseAndClearDiskCache
Closes the disk cache and deletes all files in the cache directory including files that weren't created by the cache.
CloseDiskCache
Closes the disk cache. Stored values will remain on the filesystem.
CopyFileToDisk
(
key
As
String
,
dir
As
String
,
filename
As
String
)
Copies a file in the disk cache.
CopyFileToDisk_Async
(
key
As
String
,
dir
As
String
,
filename
As
String
,
eventPrefix
As
String
)
Copies a file in the disk cache (asynchronously).
eventPrefix
= prefix of the "CopyDone" event.
An event is triggered when the job ends. You can get it with:
Sub eventPrefix_CopyDone(key As String, Error As Boolean)
Error
is true if there was an error.
DiskFree
As
Long
Returns the available space in bytes of the disk cache.
DiskJournal
As
List
Returns a copy of the journal of the disk cache.
Example:
Dim l As List
l = myCache.DiskJournal
For i = 0 To l.Size - 1
Log(l.Get(i))
Next
DiskList
As
Map
Returns a list of the current contents of the disk cache, unordered.
Map structure: key=filename, value=object array (0=time of the last modification, 1=size in bytes)
Example:
Dim m As Map
m = myCache.DiskList
Dim Info(2) As Object
For i = 0 To m.Size - 1
Log(m.GetKeyAt(i))
Info = m.GetValueAt(i)
Log(" " & DateTime.Date(Info(0)) & " " & DateTime.Time(Info(0)))
Log(" " & Info(1) & " bytes")
Next
DiskUsed
As
Long
Returns the sum of the sizes in bytes of the files in the disk cache.
FreeMemory
As
Long
[read
only]
Gets an approximation of the amount (in bytes) of free memory available to the running program.
GetBitmap
(
key
As
String
,
updateMemory
As
Boolean
)
As
android
.
graphics
.
Bitmap
Returns the bitmap for
key
from one of the caches (the memory cache is looked first).
Returns null if the key was not found.
The bitmap source (memory or disk cache) is specified in the log.
updateMemory
= if true, the memory cache is updated if the bitmap was only on disk.
GetBitmap_Async
(
key
As
String
,
updateMemory
As
Boolean
,
eventPrefix
As
String
)
Returns the given bitmap for
key
from one of the caches.
If the bitmap is in memory, it is sent back immediately. Otherwise, it is loaded from disk asynchronously.
updateMemory
= if true, the memory cache is updated if the bitmap was only found on disk.
eventPrefix
= prefix of the "GetDone" event.
An event is triggered when the job ends. You can get it with:
Sub eventPrefix_GetDone(key As String, bmp As Bitmap)
bmp
is null if the key was not found or there was an error.
GetBitmapFromDisk
(
key
As
String
,
colorReduction
As
Boolean
)
As
android
.
graphics
.
Bitmap
Returns the bitmap for
key
from the disk cache.
Returns null if the key was not found.
colorReduction
= if True, the number of colors is reduced to save memory. This setting has no effect if some pixels are not opaque.
GetBitmapFromDisk_Async
(
key
As
String
,
colorReduction
As
Boolean
,
eventPrefix
As
String
)
Returns the bitmap for
key
from the disk cache (asynchronously).
colorReduction
= if True, the number of colors is reduced to save memory. This setting has no effect if some pixels are not opaque.
eventPrefix
= prefix of the "GetDone" event.
An event is triggered when the job ends. You can get it with:
Sub eventPrefix_GetDone(key As String, bmp As Bitmap)
bmp
is null if the key was not found or there was an error.
GetBitmapFromMemory
(
key
As
String
)
As
android
.
graphics
.
Bitmap
Returns the Bitmap for
key
if it exists in the cache.
Returns null if not found.
GetDirectory
As
String
Returns the directory where the disk cache stores its data.
GetObjectFromDisk
(
key
As
String
)
As
Object
Returns the object for
key
from the disk cache.
Returns null if the key was not found.
GetObjectFromDisk_Async
(
key
As
String
,
eventPrefix
As
String
)
Returns the object for
key
from the disk cache (asynchronously).
eventPrefix
= prefix of the "GetDone" event.
An event is triggered when the job ends. You can get it with:
Sub eventPrefix_GetDone(key As String, obj As Object)
obj
is null if the key was not found or there was an error.
GetStringFromDisk
(
key
As
String
)
As
String
Gets the string for
key
from the disk cache.
Returns an empty string if the key was not found.
Initialize
(
memoryCachePct
As
Byte
,
diskCacheSize
As
Long
,
diskCacheDir
As
String
)
Initializes the caches.
memoryCachePct
: percentage of free memory to use for the memory cache (this cache is only used for bitmaps, the other objects are stored on disk). Cannot exceed 90.
diskCacheSize
: size in bytes of the cache on disk.
diskCacheDir
: folder where the cache files are stored.
If empty, the default cache folder is used. This folder is specific to the application.
Example:
myCache.Initialize(25, 20 * 1024 * 1024, "/mnt/sdcard/myAppCache")
'25% for the memory cache and 20MB for the disk cache
IsClosed
As
Boolean
Returns true if the disk cache has been closed.
IsInMemory
(
key
As
String
)
As
Boolean
Returns true if the Bitmap for
key
is still in the memory cache.
IsOnDisk
(
key
As
String
)
As
Boolean
Returns true if the file for
key
is still in the disk cache.
MaxMemory
As
Long
[read
only]
Gets the maximum amount of memory (in bytes) that may be used by the running program.
MemoryEvictionCount
As
Int
Returns the number of bitmaps that have been evicted from the memory cache.
MemoryFree
As
Int
Returns the available space in bytes of the memory cache.
MemoryHitCount
As
Int
Returns the number of times
GetBitmapFromMemory
returned a bitmap that was present in the cache.
MemoryList
As
Map
Returns a copy of the current contents of the memory cache, ordered from least recently accessed to most recently accessed.
MemoryMissCount
As
Int
Returns the number of times
GetBitmapFromMemory
returned null (bitmap not found).
MemoryPutCount
As
Int
Returns the number of times
PutBitmapInMemory
was called.
MemoryUsed
As
Int
Returns the sum of the sizes in bytes of the entries in the memory cache.
PutBitmapInMemory
(
key
As
String
,
bitmap
As
BitmapWrapper
)
As
Boolean
Caches the given bitmap in memory.
Returns false if the bitmap is too big for the cache.
PutBitmapOnDisk
(
key
As
String
,
bitmap
As
BitmapWrapper
,
format
As
String
,
quality
As
Int
)
Stores the given bitmap in the disk cache.
Format
: "JPEG" or "PNG"
Quality
: quality of JPEG compression (0..100). This setting is ignored for the PNG format.
PutBitmapOnDisk_Async
(
key
As
String
,
bitmap
As
BitmapWrapper
,
format
As
String
,
quality
As
Int
,
eventPrefix
As
String
)
Stores the given bitmap in the disk cache (asynchronously).
Format
: "JPEG" or "PNG"
Quality
: quality of JPEG compression (0..100). This setting is ignored for the PNG format.
eventPrefix
= prefix of the "PutDone" event.
An event is triggered when the job ends. You can get it with:
Sub eventPrefix_PutDone(key As String, Error As Boolean)
Error
is true if there was an error.
PutObjectOnDisk
(
key
As
String
,
obj
As
Object
)
Stores the given object in the disk cache.
This works only with serializable objects (numbers, booleans, lists, arrays...).
PutObjectOnDisk_Async
(
key
As
String
,
obj
As
Object
,
eventPrefix
As
String
)
Stores the given object in the disk cache (asynchronously).
This works only with serializable objects (numbers, booleans, lists, arrays...).
eventPrefix
= prefix of the "PutDone" event.
An event is triggered when the job ends. You can get it with:
Sub eventPrefix_PutDone(key As String, Error As Boolean)
Error
is true if there was an error.
PutStringOnDisk
(
key
As
String
,
value
As
String
)
Stores the given string in the disk cache.
RemoveBitmapFromMemory
(
key
As
String
)
Removes the Bitmap for
key
if it exists.
RemoveFromDisk
(
key
As
String
)
As
Boolean
Removes the file for
key
if it exists in the disk cache.
Returns true if the file was removed.
Top