要将一些信息存放到内存中,要求在内存中保留最近的n条信息供查询,请问有什么方法可以做到

解决方案 »

  1.   

    你是什么程序啊,桌面还是web?web的话session了,桌面就不存在了吧,数组就可以了,.....
      

  2.   

    LRU缓存啊用LinkedHashMap就可以做到,可以搜索一下"java LRU缓存"
      

  3.   

    用ibatis查询数据库, 也可设置缓存
      <select id="getADRootList" resultMap="result" cacheModel="adCache">
       select * from px_ad where type!='3'
      </select><cacheModel type="LRU" id="adCache" readOnly="false" serialize="true">
    这里可以设置多长时间刷新一次,或是在什么操作之后刷新
    </cacheModel>
      

  4.   

    一般的数据结构都可以:map、list、queue或者stack等等。