PHP高效文件缓存类FCache

Home / Article MrLee 2015-8-3 2893

u=3395780984,1127761943&fm=58

自己用的阿里云低配置,最近访问不错,经常出现mysql崩溃的问题,提单说请加内存,这回复还不如直接说:请交钱!
于是自己在git找了php的文件缓存,发现都是将缓存放到一个缓存文件!!!意味着:
1.无论你是读取多大的数据,都需要从磁盘读出整个文件到内存,然后解析,获取你要的部分数据;
2.在缓存数据很大的时候,并不能起到缓存加速网站访问的目的,同时增加磁盘的读写负荷;
3.在某一个临界点,可能会导致缓存性能比数据库还差;
4.未经过严格测试,个人预估一般网站的数据都会达到100M以上,如果每次访问需要读取100M的数据,然后解析,性能非常低效。
感觉这些写开源项目的作者写完之后,自己肯定没有做相关的时间测试,虽然我自己也没有做测试,于是自己按照自己的需求写了一个fcache.inc.php
php-file-cache-master
PHP File Cache, Used to instead of memcache in Host which can not install memcache.
1.one cache, one file, reduce calculate of key and value, to gain hign performaance.
2.simple api to use. similar with memcache.
使用很简单,Demo
 time(),
      'str' => 'test',
      'int'   => 1321
);
$cache->add('select * from table;', $storeData);
$cache->add('select * from table;', $storeData);
$cache->add('select * from table;', $storeData);
$cache->add('select * from table;', $storeData);
print_r($storeData = $cache->get('select * from table;'));
$cache->delete('select * from table;');
print_r ($cache->get('select * from table;') ? 'exist': 'has no cache');
$cache->add('select * from table1;', 123);
$cache->add('select * from table2;', 234);
$cache->add('select * from table3;', 345);
$cache->flush();
print_r ($cache->get('select * from table3;') ? 'exist': 'has no cache');
?>

本文链接:https://www.it72.com/3941.htm

推荐阅读
最新回复 (0)
返回