!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache. PHP/5.6.40 

uname -a: Linux cpanel06wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.80.el6.x86_64 #1 SMP Thu Sep 24
01:42:00 EDT 2020 x86_64
 

uid=851(cp949260) gid=853(cp949260) groups=853(cp949260) 

Safe-mode: OFF (not secure)

/opt/alt/php74/usr/include/php/ext/swoole/include/   drwxr-xr-x
Free 233.72 GB of 981.82 GB (23.8%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     lru_cache.h (2.29 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#pragma once

#include <unordered_map>
#include <list>
#include <utility>
#include <memory>
#include <time.h>

namespace swoole
{
/**
 * This cache isn't thread safe
 */
class LRUCache
{
private:
    typedef std::pair<time_t, std::shared_ptr<void>> cache_node_t;
    typedef std::list<std::pair<std::string, cache_node_t>> cache_list_t;

    std::unordered_map<std::string, cache_list_t::iterator> cache_map;
    cache_list_t cache_list;
    size_t cache_capacity;

public:
    explicit LRUCache(size_t capacity)
    {
        cache_capacity = capacity;
    }

    inline std::shared_ptr<void> get(const std::string &key)
    {
        auto iter = cache_map.find(key);
        if (iter == cache_map.end())
        {
            return nullptr;
        }

        if (iter->second->second.first < time(nullptr) && iter->second->second.first > 0)
        {
            return nullptr;
        }

        cache_list.splice(cache_list.begin(), cache_list, iter->second);
        return iter->second->second.second; // iter -> list::iter -> cache_node_t -> value
    }

    inline void set(const std::string &key, const std::shared_ptr<void> &val, time_t expire = 0)
    {
        time_t expire_time;

        if (expire <= 0)
        {
            expire_time = 0;
        }
        else
        {
            expire_time = time(nullptr) + expire;
        }

        auto iter = cache_map.find(key);
        if (iter != cache_map.end())
        {
            iter->second->second.first = expire_time;
            iter->second->second.second = val;
            cache_list.splice(cache_list.begin(), cache_list, iter->second);
            return;
        }

        size_t size = cache_list.size();
        if (size == cache_capacity && size > 0)
        {
            auto del = cache_list.back();
            cache_map.erase(del.first);
            cache_list.pop_back();
        }

        cache_list.emplace_front(key, cache_node_t{expire_time, val});
        cache_map[key] = cache_list.begin();
    }

    inline void del(const std::string &key)
    {
        auto iter = cache_map.find(key);
        if (iter == cache_map.end())
        {
            return;
        }

        cache_list.erase(iter->second);
        cache_map.erase(iter);
    }

    inline void clear()
    {
        cache_list.clear();
        cache_map.clear();
    }
};
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0292 ]--