dp610807 2011-02-23 22:04
浏览 66
已采纳

APC缓存文件与缓存变量

Say I have a file a.php which only contains a large array:

$client = array(
    "a" => 123,
    "b" => 124,
    ...
 );

APC caches the file a.php but what does that mean exactly? It caches the opcode for the assignment only? Does it actually cache the mapping itself? Or do I need to explicitly put that in the APC cache?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongtan5558 2011-02-23 22:21
    关注

    APC caches a PHP file in byte code. This is a faster intermediary between human readable code and what the interpreter ends up executing. This is analogous to compiling a C/C++ file into a binary. An array compiled in this fashion will load quicker than if you read it form file.

    Accessing an element in an associative array in php is constant time O(1) in Big-O. Adding an element is also O(1). By and large its best to store such arrays in the database because it uses less memory and is much more flexible. Keep in mind that every browser that visits this application is going to have its own copy of this array, where as if you use a database there would be only one copy. For instance if you want to look up a key based on its value you'll have to iterate over it which is O(n) (which is slow), the use of a database will be much faster.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 等差数列中的素数个数
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证