project.player.PlaylistCache = new Class({
    Implements: [Options, project.player.Logging],

    log_prefix: 'Cache',

    cache: [],

    initialize: function()
    {
        this.logger('initialize');
    },

    addPageItems: function(playlist_id, page, playlist_items)
    {
        this.logger('addPageItems: ' + playlist_id + ' (' + page + ')');
        if(undefined === this.cache[playlist_id])
        {
            var cache_obj = {};
            cache_obj[page] = playlist_items;
            this.cache[playlist_id] = cache_obj;
        }
        else
        {
            this.cache[playlist_id][page] = playlist_items;
        }
    },

    setPlaylistPageCount: function(playlist_id, page_count)
    {
        if(undefined === this.cache[playlist_id])
        {
            this.cache[playlist_id] = {};
        }
        this.cache[playlist_id]['page_count'] = page_count;
    },

    getPlaylistPageCount: function(playlist_id)
    {
        return this.cache[playlist_id]['page_count'];
    },

    getPageItems: function(playlist_id, page)
    {
        this.logger('getPageItems: ' + playlist_id + ' (' + page + ')');
        var items = null;
        if(undefined === this.cache[playlist_id])
        {
            return null;
        }
        if(undefined !== this.cache[playlist_id][page])
        {
            items = this.cache[playlist_id][page];
        }
        
        return items;
    },

    listCache: function()
    {
        var that = this;
        that.logger('list cached playlists');
        that.cache.each(function(page, playlist_id) {
            that.logger( [playlist_id, page] );
        });
    }
});

