我在系统中缓存了user对象,同时user对象中关联实体company,office两个对象 
同时我的所有的用户的添加修改都会对缓存进行操作.即清除重写 但是,如果我修改了company对象后,缓存中的user对象没有进行缓存修改处理,则登录用户从user.getCompany()中取出来的还是原来 的公司名称.如:缓存中的公司名称是A,而更改后的是B,则如果从user.getCompany()取出来的还是A,但是实际上数据库当中已经是B了,我该如何做? 如果是我对company进行了修改后,关联修改user对象,则不会有上述问题.但是如果公司下面的用户过多的话,那么效率会很低的啊.况且我的用户下面还关联了很多的角色,权限信息. 
大家有什么好的方法吗? 

解决方案 »

  1.   

    <cache name="com.sdcncsi.entity.sys.Area" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Area.staffs" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Area.offices" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Office" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Staff" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Staff.area" maxElementsInMemory="500" overflowToDisk="true"
    eternal="false" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Staff.roles" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Role" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Role.staffs" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Role.privileges" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache> <cache name="com.sdcncsi.entity.sys.Privilege" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120"/>
    <cache name="com.sdcncsi.entity.sys.Privilege.roles" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120"/>        
    <cache name="com.sdcncsi.entity.sys.Privilege.resources" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120"/>
    <cache name="com.sdcncsi.entity.sys.Resource" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200"  
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120"/>
      

  2.   

    我的user数据是在系统启动 时读取到缓存中去的.
    登录的时候,读取用户信息也是从缓存中读取的.
    不过我增加修改用户信息都要添加到缓存中.但是就是对company(也就是配置文件中的area)无法关联.难道是没有配置级联吗?
      

  3.   

    以Staff和Area为例,你把
    <cache name="com.sdcncsi.entity.sys.Area" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200" 
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Staff" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200" 
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Staff.area" maxElementsInMemory="500" overflowToDisk="true"
    eternal="false" timeToIdleSeconds="1200" timeToLiveSeconds="7200" 
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    改成
    <cache name="com.sdcncsi.entity.sys.Area" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200" 
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    <cache name="com.sdcncsi.entity.sys.Staff" maxElementsInMemory="500" overflowToDisk="true"
    eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="7200" 
            diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
    </cache>
    也就是说不要缓存Staff的area这个关系。
      

  4.   

    这样的:
    我的用户列表当中的数据,如果company由A改为B后已经显示成为B了,但是
    我放入上下文中的信息却还是A,我用的是springSecurity,它的上下文中的信息还是A我不知道你是否胜过这个安全框架,也就是acegi
      

  5.   

    上下文中放置了一个staff对象,它会有关联的company对象
    我一般都会通过staff.getCompany()来取的.当然了,用户列表当中的getCompany().getCompnayName()是正确的.
    而上下文中的那个却是错误的.难道我们需要手动清除吗?
      

  6.   

    这样的话,你不要在springsecurity上下文里保存staff对象,只要保存一个staff id就行了。每次要用的时候,取出这个id,从hibernate里查询对应的staff实例。