0
package net.flying_saucer.util {
0
import flash.net.SharedObject
0
+ import flash.utils.getTimer
0
+ import flash.utils.setTimeout
0
// =========================================================================
0
- private static var _cache:SharedObject = SharedObject.getLocal('fsCache', '/')
0
+ private static var _cache:SharedObject = SharedObject.getLocal('fsCache', '/'),
0
+ flush_pending:Boolean = false,
0
@@ -22,32 +26,45 @@ package net.flying_saucer.util {
0
_cache.data[key] = null
0
- public static function flush():void {
0
public static function read(key:String):* {
0
return _cache.data[key]
0
- public static function write(key:String, val:*
, f:Boolean = false):* {
0
+ public static function write(key:String, val:*
):* {
0
// Public Methods for Cached Arrays
0
// =========================================================================
0
- public static function append(key:String, val:*
, f:Boolean = false):Array {
0
+ public static function append(key:String, val:*
):Array {
0
var a:Array = read(key) || []
0
- return write(key, a
, f)
0
- public static function prepend(key:String, val:*
, f:Boolean = false):Array {
0
+ public static function prepend(key:String, val:*
):Array {
0
var a:Array = read(key) || []
0
- return write(key, a, f)
0
+ // =========================================================================
0
+ // Flush with safety mechanism to flush to disk no more than once per second
0
+ private static function flush():void {
0
+ var time_since_last_flush:int = getTimer() - last_flush
0
+ if(time_since_last_flush > 1000) {
0
+ last_flush = getTimer()
0
+ } else if(!flush_pending) {
0
+ setTimeout(flush, 1001 - time_since_last_flush)
Comments
No one has commented yet.